File tree Expand file tree Collapse file tree 1 file changed +7
-3
lines changed Expand file tree Collapse file tree 1 file changed +7
-3
lines changed Original file line number Diff line number Diff line change 9
9
if __name__ == "__main__" :
10
10
pytest_args = ["--ignore=external" ]
11
11
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
+
12
16
if os .environ .get ("XML_OUTPUT_FILE" ):
13
17
pytest_args .append ("--junitxml={xml_output_file}" .format (xml_output_file = os .environ .get ("XML_OUTPUT_FILE" )))
14
18
19
23
# If the test filter does not start with a class-like name, then use test filtering instead
20
24
# --test_filter=test_fn
21
25
if not module_name [0 ].isupper ():
22
- pytest_args .extend (sys . argv [ 1 :] )
26
+ pytest_args .extend (args )
23
27
pytest_args .append ("-k={filter}" .format (filter = module_name ))
24
28
else :
25
29
# --test_filter=TestClass.test_fn
26
30
# Add test filter to path-like args
27
- for arg in sys . argv [ 1 :] :
31
+ for arg in args :
28
32
if not arg .startswith ("--" ):
29
33
# Maybe a src file? Add test class/method selection to it. Not sure if this will work if the
30
34
# symbol can't be found in the test file.
31
35
arg = "{arg}::{module_fn}" .format (arg = arg , module_fn = module_name )
32
36
pytest_args .append (arg )
33
37
else :
34
- pytest_args .extend (sys . argv [ 1 :] )
38
+ pytest_args .extend (args )
35
39
36
40
print (pytest_args , file = sys .stderr )
37
41
raise SystemExit (pytest .main (pytest_args ))
You can’t perform that action at this time.
0 commit comments