-
Notifications
You must be signed in to change notification settings - Fork 207
Expand file tree
/
Copy pathconftest.py
More file actions
59 lines (44 loc) · 1.39 KB
/
conftest.py
File metadata and controls
59 lines (44 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import pytest
import pytest_asyncio
import os
from logging import warning
from e2b_code_interpreter.code_interpreter_async import AsyncSandbox
from e2b_code_interpreter.code_interpreter_sync import Sandbox
timeout = 60
@pytest.fixture()
def template():
return os.getenv("E2B_TESTS_TEMPLATE") or "code-interpreter-v1"
@pytest.fixture()
def sandbox(template, debug):
sandbox = Sandbox(template, timeout=timeout, debug=debug)
try:
yield sandbox
finally:
try:
sandbox.kill()
except:
if not debug:
warning(
"Failed to kill sandbox — this is expected if the test runs with local envd."
)
@pytest_asyncio.fixture
async def async_sandbox(template, debug):
async_sandbox = await AsyncSandbox.create(template, timeout=timeout, debug=debug)
try:
yield async_sandbox
finally:
try:
await async_sandbox.kill()
except:
if not debug:
warning(
"Failed to kill sandbox — this is expected if the test runs with local envd."
)
@pytest.fixture
def debug():
return os.getenv("E2B_DEBUG") is not None
@pytest.fixture(autouse=True)
def skip_by_debug(request, debug):
if request.node.get_closest_marker("skip_debug"):
if debug:
pytest.skip("skipped because E2B_DEBUG is set")