@@ -23,9 +23,11 @@ def setup_modifier_factory():
23
23
assert ModifierFactory ._loaded , "ModifierFactory not loaded"
24
24
25
25
26
- def _get_files (directory : str ) -> List [str ]:
26
+ def _get_files (directory : str , ignore_dirs : List [ str ] = [] ) -> List [str ]:
27
27
list_filepaths = []
28
+ ignore_dirs = tuple (ignore_dirs ) # has to be a tuple for str.startswith
28
29
for root , dirs , files in os .walk (directory ):
30
+ dirs [:] = [dir_ for dir_ in dirs if not str (dir_ ).startswith (ignore_dirs )]
29
31
for file in files :
30
32
list_filepaths .append (os .path .join (os .path .abspath (root ), file ))
31
33
return list_filepaths
@@ -46,8 +48,11 @@ def _files_size_mb(path_list: List[str]) -> int:
46
48
47
49
@pytest .fixture (scope = "session" , autouse = True )
48
50
def check_for_created_files ():
49
- start_files_root = _get_files (directory = r"." )
50
- start_files_temp = _get_files (directory = tempfile .gettempdir ())
51
+ ignore_dirs = ["__pycache__" , "sparse_logs" ]
52
+ start_files_root = _get_files (directory = r"." , ignore_dirs = ignore_dirs )
53
+ start_files_temp = _get_files (
54
+ directory = tempfile .gettempdir (), ignore_dirs = ["pytest-of" ]
55
+ )
51
56
yield
52
57
if wandb :
53
58
wandb .finish ()
@@ -56,10 +61,7 @@ def check_for_created_files():
56
61
shutil .rmtree (log_dir )
57
62
58
63
# allow creation of __pycache__ directories
59
- end_files_root = [
60
- f_path for f_path in _get_files (directory = r"." ) if "__pycache__" not in f_path
61
- ]
62
- end_files_temp = _get_files (directory = tempfile .gettempdir ())
64
+ end_files_root = _get_files (directory = r"." , ignore_dirs = ignore_dirs )
63
65
# assert no files created in root directory while running
64
66
# the pytest suite
65
67
assert len (start_files_root ) >= len (end_files_root ), (
@@ -70,12 +72,11 @@ def check_for_created_files():
70
72
)
71
73
72
74
max_allowed_sized_temp_files_megabytes = 1
73
- end_files_temp = _get_files (directory = tempfile .gettempdir ())
74
- created_temp_files = set (end_files_temp ) - set (start_files_temp )
75
75
# pytest temp files are automatically deleted, exclude from size calculation
76
- created_temp_files = [
77
- f_path for f_path in created_temp_files if "pytest-of" not in f_path
78
- ]
76
+ end_files_temp = _get_files (
77
+ directory = tempfile .gettempdir (), ignore_dirs = ["pytest-of" ]
78
+ )
79
+ created_temp_files = set (end_files_temp ) - set (start_files_temp )
79
80
80
81
# assert no more than 1 megabyte of temp files created in temp directory
81
82
# while running the pytest suite (excluding files created by pytest)
0 commit comments