Skip to content

Commit cfcbfc8

Browse files
committed
fix: Update test_list_files_recursively to use isolated temp directory for json files
Signed-off-by: Onuralp SEZER <onuralp@ultralytics.com>
1 parent 37ea556 commit cfcbfc8

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

tests/test_file_utils.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,21 @@ def test_list_files(self):
1212
filepath_list = list_files(directory, contains=["json"], verbose=False)
1313
assert len(filepath_list) == 11
1414

15-
def test_list_files_recursively(self):
15+
def test_list_files_recursively(self, tmp_path):
16+
import shutil
17+
from pathlib import Path
18+
1619
from sahi.utils.file import list_files_recursively
1720

18-
directory = "tests/data/coco_utils/"
21+
# Copy only the target json files into an isolated temp directory to avoid race
22+
# with other tests that may create additional *coco.json files recursively.
23+
src_dir = Path("tests/data/coco_utils/")
24+
for f in src_dir.iterdir():
25+
if f.is_file() and "coco.json" in f.name:
26+
shutil.copy(f, tmp_path / f.name)
27+
1928
relative_filepath_list, abs_filepath_list = list_files_recursively(
20-
directory, contains=["coco.json"], verbose=False
29+
str(tmp_path), contains=["coco.json"], verbose=False
2130
)
2231
assert len(relative_filepath_list) == 7
2332
assert len(abs_filepath_list) == 7

0 commit comments

Comments
 (0)