File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 99if __name__ == "__main__" :
1010 pytest_args = ["--ignore=external" ]
1111
12+ # pytest runs tests twice if __init__.py is passed explicitly as an argument. Remove any __init__.py file to avoid that.
13+ # https://github.com/pytest-dev/pytest/issues/9313
14+ args = [arg for arg in sys .argv [1 :] if arg .startswith ("-" ) or os .path .basename (arg ) != "__init__.py" ]
15+
1216 if os .environ .get ("XML_OUTPUT_FILE" ):
1317 pytest_args .append ("--junitxml={xml_output_file}" .format (xml_output_file = os .environ .get ("XML_OUTPUT_FILE" )))
1418
1923 # If the test filter does not start with a class-like name, then use test filtering instead
2024 # --test_filter=test_fn
2125 if not module_name [0 ].isupper ():
22- pytest_args .extend (sys . argv [ 1 :] )
26+ pytest_args .extend (args )
2327 pytest_args .append ("-k={filter}" .format (filter = module_name ))
2428 else :
2529 # --test_filter=TestClass.test_fn
2630 # Add test filter to path-like args
27- for arg in sys . argv [ 1 :] :
31+ for arg in args :
2832 if not arg .startswith ("--" ):
2933 # Maybe a src file? Add test class/method selection to it. Not sure if this will work if the
3034 # symbol can't be found in the test file.
3135 arg = "{arg}::{module_fn}" .format (arg = arg , module_fn = module_name )
3236 pytest_args .append (arg )
3337 else :
34- pytest_args .extend (sys . argv [ 1 :] )
38+ pytest_args .extend (args )
3539
3640 print (pytest_args , file = sys .stderr )
3741 raise SystemExit (pytest .main (pytest_args ))
You can’t perform that action at this time.
0 commit comments