Skip to content

Commit 483830e

Browse files
dobraccursoragent
andauthored
Update e2b dependency to latest version (#176)
Co-authored-by: jakub.dobry <jakub.dobry@e2b.dev> Co-authored-by: Cursor Agent <cursoragent@cursor.com>
1 parent 8df1ba6 commit 483830e

File tree

5 files changed

+111
-64
lines changed

5 files changed

+111
-64
lines changed

js/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,6 @@
7474
"defaults"
7575
],
7676
"dependencies": {
77-
"e2b": "^2.6.0"
77+
"e2b": "^2.7.0"
7878
}
7979
}

pnpm-lock.yaml

Lines changed: 8 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

python/poetry.lock

Lines changed: 53 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

python/pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ python = "^3.9"
1414

1515
httpx = ">=0.20.0, <1.0.0"
1616
attrs = ">=21.3.0"
17-
e2b = "^2.6.0"
17+
e2b = "^2.7.0"
1818

1919
[tool.poetry.group.dev.dependencies]
20-
pytest = "^7.4.0"
20+
pytest = "^8.2.0"
2121
python-dotenv = "^1.0.0"
2222
pytest-dotenv = "^0.5.2"
23-
pytest-asyncio = "^0.23.7"
23+
pytest-asyncio = "^0.24.0"
2424
pytest-xdist = "^3.6.1"
2525
pydoc-markdown = "^4.8.2"
2626
matplotlib = "^3.8.0"

python/tests/conftest.py

Lines changed: 46 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import pytest
22
import pytest_asyncio
33
import os
4+
import asyncio
45

56
from logging import warning
67

@@ -10,6 +11,19 @@
1011
timeout = 60
1112

1213

14+
# Override the event loop so it never closes during test execution
15+
# This helps with pytest-xdist and prevents "Event loop is closed" errors
16+
@pytest.fixture(scope="session")
17+
def event_loop():
18+
"""Create a session-scoped event loop for all async tests."""
19+
try:
20+
loop = asyncio.get_running_loop()
21+
except RuntimeError:
22+
loop = asyncio.new_event_loop()
23+
yield loop
24+
loop.close()
25+
26+
1327
@pytest.fixture()
1428
def template():
1529
return os.getenv("E2B_TESTS_TEMPLATE") or "code-interpreter-v1"
@@ -31,20 +45,39 @@ def sandbox(template, debug):
3145
)
3246

3347

34-
@pytest_asyncio.fixture
35-
async def async_sandbox(template, debug):
36-
async_sandbox = await AsyncSandbox.create(template, timeout=timeout, debug=debug)
48+
@pytest.fixture
49+
def async_sandbox_factory(request, template, debug, event_loop):
50+
"""Factory for creating async sandboxes with proper cleanup."""
3751

38-
try:
39-
yield async_sandbox
40-
finally:
41-
try:
42-
await async_sandbox.kill()
43-
except: # noqa: E722
44-
if not debug:
45-
warning(
46-
"Failed to kill sandbox — this is expected if the test runs with local envd."
47-
)
52+
async def factory(template_override=None, **kwargs):
53+
template_name = template_override or template
54+
kwargs.setdefault("timeout", timeout)
55+
kwargs.setdefault("debug", debug)
56+
57+
sandbox = await AsyncSandbox.create(template_name, **kwargs)
58+
59+
def kill():
60+
async def _kill():
61+
try:
62+
await sandbox.kill()
63+
except: # noqa: E722
64+
if not debug:
65+
warning(
66+
"Failed to kill sandbox — this is expected if the test runs with local envd."
67+
)
68+
69+
event_loop.run_until_complete(_kill())
70+
71+
request.addfinalizer(kill)
72+
return sandbox
73+
74+
return factory
75+
76+
77+
@pytest.fixture
78+
async def async_sandbox(async_sandbox_factory):
79+
"""Default async sandbox fixture."""
80+
return await async_sandbox_factory()
4881

4982

5083
@pytest.fixture

0 commit comments

Comments
 (0)