File tree Expand file tree Collapse file tree 2 files changed +28
-2
lines changed
Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Original file line number Diff line number Diff line change 33markers =
44 skip_debug: skip test if E2B_DEBUG is set.
55asyncio_mode =auto
6- asyncio_default_fixture_loop_scope =function
76
87addopts = " --import-mode=importlib" " --numprocesses=2"
Original file line number Diff line number Diff line change 11import pytest
22import pytest_asyncio
33import os
4+ import asyncio
45
56from logging import warning
67
1011timeout = 60
1112
1213
14+ @pytest_asyncio .fixture (scope = "function" )
15+ def event_loop ():
16+ """Create an instance of the default event loop for each test case."""
17+ policy = asyncio .get_event_loop_policy ()
18+ loop = policy .new_event_loop ()
19+ yield loop
20+ # Clean up any remaining tasks
21+ try :
22+ pending = asyncio .all_tasks (loop )
23+ for task in pending :
24+ task .cancel ()
25+ if pending :
26+ loop .run_until_complete (asyncio .gather (* pending , return_exceptions = True ))
27+ except Exception :
28+ pass
29+ # Close the loop gracefully
30+ try :
31+ loop .close ()
32+ except Exception :
33+ pass
34+
35+
1336@pytest .fixture ()
1437def template ():
1538 return os .getenv ("E2B_TESTS_TEMPLATE" ) or "code-interpreter-v1"
@@ -31,7 +54,7 @@ def sandbox(template, debug):
3154 )
3255
3356
34- @pytest_asyncio .fixture
57+ @pytest_asyncio .fixture ( loop_scope = "function" )
3558async def async_sandbox (template , debug ):
3659 async_sandbox = await AsyncSandbox .create (template , timeout = timeout , debug = debug )
3760
@@ -40,6 +63,10 @@ async def async_sandbox(template, debug):
4063 finally :
4164 try :
4265 await async_sandbox .kill ()
66+ except RuntimeError as e :
67+ # Ignore "Event loop is closed" errors during cleanup in pytest-xdist
68+ if "Event loop is closed" not in str (e ):
69+ raise
4370 except : # noqa: E722
4471 if not debug :
4572 warning (
You can’t perform that action at this time.
0 commit comments