5555
5656ALLOWED_SUB_FOLDERS_OF_TESTS = ["unit" , "system" , "integration" ]
5757
58- should_fail = False
59- fatal_error = False
58+
59+ class _ErrorSignals :
60+ should_fail : bool = False
61+ fatal_error : bool = False
62+
63+
6064missing_init_dirs : list [Path ] = []
6165missing_path_extension_dirs : list [Path ] = []
6266
@@ -77,11 +81,9 @@ def _what_kind_of_test_init_py_needed(base_path: Path, folder: Path) -> tuple[bo
7781 if folder .name not in ALLOWED_SUB_FOLDERS_OF_TESTS :
7882 console .print (f"[red]Unexpected folder { folder } in { base_path } [/]" )
7983 console .print (f"[yellow]Only { ALLOWED_SUB_FOLDERS_OF_TESTS } should be sub-folders of tests.[/]" )
80- global should_fail
81- global fatal_error
82- should_fail = True
83- fatal_error = True
84- return False , False
84+ _ErrorSignals .should_fail = True
85+ _ErrorSignals .fatal_error = True
86+ return True , True
8587 if depth == 2 :
8688 # For known sub-packages that can occur in several packages we need to add __path__ extension
8789 return True , folder .name in KNOWN_SECOND_LEVEL_PATHS
@@ -162,20 +164,20 @@ def check_dir_init_src_folders(folders: list[Path]) -> None:
162164 init_file = missing_init_dir / "__init__.py"
163165 init_file .write_text ("" .join (prefixed_licensed_txt ))
164166 console .print (f"[yellow]Added missing __init__.py file:[/] { init_file } " )
165- should_fail = True
167+ _ErrorSignals . should_fail = True
166168
167169 for missing_extension_dir in missing_path_extension_dirs :
168170 init_file = missing_extension_dir / "__init__.py"
169171 init_file .write_text (init_file .read_text () + PATH_EXTENSION_STRING + "\n " )
170172 console .print (f"[yellow]Added missing path extension to __init__.py file[/] { init_file } " )
171- should_fail = True
173+ _ErrorSignals . should_fail = True
172174
173- if should_fail :
175+ if _ErrorSignals . should_fail :
174176 console .print (
175177 "\n [yellow]The missing __init__.py files have been created. "
176178 "Please add these new files to a commit."
177179 )
178- if fatal_error :
180+ if _ErrorSignals . fatal_error :
179181 console .print ("[red]Also please remove the extra test folders listed above!" )
180182 sys .exit (1 )
181183 console .print ("[green]All __init__.py files are present and have necessary extensions.[/]" )
0 commit comments