Skip to content

Commit bc45f70

Browse files
committed
refactor change docker test result dir to pytest tmp_path
1 parent 9eeb486 commit bc45f70

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed
Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
import os
2-
import shutil
3-
41
import pytest
2+
from pathlib import Path
53

64
from backend.config.paths import (
75
ARTIFACTS_AI_CSV_FILE,
@@ -16,40 +14,43 @@
1614
TEST_RESOURCES_DIR + "ExecutionTreeContributedCoverage.csv"
1715
)
1816
TEST_ARTIFACTS_AI_CSV_FILE = TEST_RESOURCES_DIR + "AI.csv"
19-
TEST_RESULTS_DIR = BASE_DIR + "/utils/tests/resources/results"
20-
21-
22-
@pytest.fixture(autouse=True)
23-
def auto_test_results_dir():
24-
os.makedirs(TEST_RESULTS_DIR, exist_ok=True)
25-
yield
26-
shutil.rmtree(TEST_RESULTS_DIR)
2717

2818

2919
@pytest.fixture
30-
def mock_paths(monkeypatch):
20+
def test_env(tmp_path, monkeypatch):
21+
results_dir = tmp_path / "results"
22+
results_dir.mkdir()
23+
3124
def mock_get_thread_filepath(uid, filepath):
3225
if "uploads" in filepath:
3326
return filepath.replace("tmp/uploads", "utils/tests/resources")
3427
if filepath == ARTIFACTS_AI_CSV_FILE:
3528
return TEST_ARTIFACTS_AI_CSV_FILE
3629
if filepath == ARTIFACTS_BASELINE_CSV_FILE:
3730
return TEST_ARTIFACTS_BASELINE_CSV_FILE
31+
32+
if "results" in filepath:
33+
return str(results_dir / Path(filepath).name)
34+
3835
return filepath.replace("tmp", "utils/tests/resources")
3936

4037
monkeypatch.setattr(docker_runner, "get_thread_filepath", mock_get_thread_filepath)
4138

39+
return {
40+
"results_dir": results_dir,
41+
}
42+
4243

43-
def test_runstrat_baseline(mock_paths):
44+
def test_runstrat_baseline(test_env):
4445
uid = "test"
4546
RunstratBaseline().run(uid)
4647

4748

48-
def test_runstrat_ai(mock_paths):
49+
def test_runstrat_ai(test_env):
4950
uid = "test"
5051
RunstratAI().run(uid)
5152

5253

53-
def test_compstrat(mock_paths):
54+
def test_compstrat(test_env):
5455
uid = "test"
5556
Compstrat().run(uid)

0 commit comments

Comments
 (0)