Skip to content

Commit 3a7f7d3

Browse files
committed
Prevent dropping files in project root
Some tests dropped files on disk, this uses tempdirs to keep the project root clean during python testing.
1 parent 952adda commit 3a7f7d3

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

python/tests/test_test_inputs.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os.path
22
import pkgutil
3+
import tempfile
34
from typing import List
45

56
import pytest
@@ -28,6 +29,14 @@ async def test_test_inputs(predictor):
2829

2930
# Some predictors calls current_scope() and requires ctx_pid
3031
scope.ctx_pid.set(predictor)
31-
assert await r.test()
32+
33+
# Use temporary directory for predictors that create files
34+
original_cwd = os.getcwd()
35+
with tempfile.TemporaryDirectory() as temp_dir:
36+
try:
37+
os.chdir(temp_dir)
38+
assert await r.test()
39+
finally:
40+
os.chdir(original_cwd)
3241
except PythonVersionError as e:
3342
pytest.skip(reason=str(e))

0 commit comments

Comments
 (0)