Skip to content

Commit 2afaa53

Browse files
author
Dylan Huang
committed
ensure test isolation
1 parent 4ae1242 commit 2afaa53

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

tests/conftest.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import os
12
import sys
3+
import tempfile
24
from pathlib import Path
35

46
import pytest
@@ -15,3 +17,39 @@
1517

1618
# Decorator to skip E2B tests when E2B is not available
1719
skip_e2b = pytest.mark.skipif(not _HAS_E2B, reason="E2B not installed")
20+
21+
22+
# ============================================================================
23+
# Test isolation for TinyDB storage
24+
# ============================================================================
25+
# Each test session gets an isolated .eval_protocol directory to prevent
26+
# concurrent test workers from corrupting the shared logs.json file.
27+
# This is especially important in CI where pytest-xdist runs tests in parallel.
28+
29+
30+
@pytest.fixture(scope="session", autouse=True)
31+
def isolated_eval_protocol_dir(tmp_path_factory):
32+
"""
33+
Create an isolated .eval_protocol directory for the test session.
34+
35+
This prevents concurrent test workers from corrupting the shared
36+
~/.eval_protocol/logs.json file when using TinyDB storage.
37+
"""
38+
# Create a unique temp directory for this test session/worker
39+
isolated_dir = tmp_path_factory.mktemp("eval_protocol")
40+
41+
# Monkeypatch the find_eval_protocol_dir function to return our isolated dir
42+
import eval_protocol.directory_utils as dir_utils
43+
44+
original_find_eval_protocol_dir = dir_utils.find_eval_protocol_dir
45+
46+
def isolated_find_eval_protocol_dir() -> str:
47+
os.makedirs(str(isolated_dir), exist_ok=True)
48+
return str(isolated_dir)
49+
50+
dir_utils.find_eval_protocol_dir = isolated_find_eval_protocol_dir
51+
52+
yield isolated_dir
53+
54+
# Restore original function after tests
55+
dir_utils.find_eval_protocol_dir = original_find_eval_protocol_dir

0 commit comments

Comments
 (0)