@@ -23,9 +23,11 @@ def setup_modifier_factory():
2323 assert ModifierFactory ._loaded , "ModifierFactory not loaded"
2424
2525
26- def _get_files (directory : str ) -> List [str ]:
26+ def _get_files (directory : str , ignore_dirs : List [ str ] = [] ) -> List [str ]:
2727 list_filepaths = []
28+ ignore_dirs = tuple (ignore_dirs ) # has to be a tuple for str.startswith
2829 for root , dirs , files in os .walk (directory ):
30+ dirs [:] = [dir_ for dir_ in dirs if not str (dir_ ).startswith (ignore_dirs )]
2931 for file in files :
3032 list_filepaths .append (os .path .join (os .path .abspath (root ), file ))
3133 return list_filepaths
@@ -46,8 +48,11 @@ def _files_size_mb(path_list: List[str]) -> int:
4648
4749@pytest .fixture (scope = "session" , autouse = True )
4850def 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+ )
5156 yield
5257 if wandb :
5358 wandb .finish ()
@@ -56,10 +61,7 @@ def check_for_created_files():
5661 shutil .rmtree (log_dir )
5762
5863 # 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 )
6365 # assert no files created in root directory while running
6466 # the pytest suite
6567 assert len (start_files_root ) >= len (end_files_root ), (
@@ -70,12 +72,11 @@ def check_for_created_files():
7072 )
7173
7274 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 )
7575 # 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 )
7980
8081 # assert no more than 1 megabyte of temp files created in temp directory
8182 # while running the pytest suite (excluding files created by pytest)
0 commit comments