Skip to content

Commit 4c2fc98

Browse files
authored
Do not mangle arguments on newer pytest versions (#11)
1 parent 7c07b39 commit 4c2fc98

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

python_pytest/pytest_shim.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@
99
if __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.
12+
args = sys.argv[1:]
13+
# pytest < 8.0 runs tests twice if __init__.py is passed explicitly as an argument.
14+
# Remove any __init__.py file to avoid that.
15+
# pytest.version_tuple is available since pytest 7.0
1316
# 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"]
17+
if not hasattr(pytest, "version_tuple") or pytest.version_tuple < (8, 0):
18+
args = [arg for arg in args if arg.startswith("-") or os.path.basename(arg) != "__init__.py"]
1519

1620
if os.environ.get("XML_OUTPUT_FILE"):
1721
pytest_args.append("--junitxml={xml_output_file}".format(xml_output_file=os.environ.get("XML_OUTPUT_FILE")))

0 commit comments

Comments
 (0)