Skip to content

Commit db3f84e

Browse files
authored
Allow specifying python version in runtests script (#10881)
This makes the script usable for packages that do not support the minimum python version hardcoded in the script. Another part of #10722
1 parent e92bfcb commit db3f84e

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

scripts/runtests.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,17 @@ def main() -> None:
5858
"only use this option if you trust the package you are testing."
5959
),
6060
)
61+
parser.add_argument(
62+
"--python-version",
63+
default=_PYTHON_VERSION,
64+
choices=("3.8", "3.9", "3.10", "3.11", "3.12"),
65+
help="Target Python version for the test (default: %(default)s).",
66+
)
6167
parser.add_argument("path", help="Path of the stub to test in format <folder>/<stub>, from the root of the project.")
6268
args = parser.parse_args()
6369
path: str = args.path
6470
run_stubtest: bool = args.run_stubtest
71+
python_version: str = args.python_version
6572

6673
path_tokens = Path(path).parts
6774
if len(path_tokens) != 2:
@@ -94,9 +101,9 @@ def main() -> None:
94101
check_new_syntax_result = subprocess.run([sys.executable, "tests/check_new_syntax.py"])
95102

96103
strict_params = _get_strict_params(path)
97-
print(f"\nRunning Pyright ({'stricter' if strict_params else 'base' } configs) for Python {_PYTHON_VERSION}...")
104+
print(f"\nRunning Pyright ({'stricter' if strict_params else 'base' } configs) for Python {python_version}...")
98105
pyright_result = subprocess.run(
99-
[sys.executable, "tests/pyright_test.py", path, "--pythonversion", _PYTHON_VERSION] + strict_params,
106+
[sys.executable, "tests/pyright_test.py", path, "--pythonversion", python_version] + strict_params,
100107
stderr=subprocess.PIPE,
101108
text=True,
102109
)
@@ -109,8 +116,8 @@ def main() -> None:
109116
pyright_returncode = pyright_result.returncode
110117
pyright_skipped = False
111118

112-
print(f"\nRunning mypy for Python {_PYTHON_VERSION}...")
113-
mypy_result = subprocess.run([sys.executable, "tests/mypy_test.py", path, "--python-version", _PYTHON_VERSION])
119+
print(f"\nRunning mypy for Python {python_version}...")
120+
mypy_result = subprocess.run([sys.executable, "tests/mypy_test.py", path, "--python-version", python_version])
114121
# If mypy failed, stubtest will fail without any helpful error
115122
if mypy_result.returncode == 0:
116123
if folder == "stdlib":
@@ -146,13 +153,13 @@ def main() -> None:
146153
pyright_testcases_skipped = False
147154
regr_test_returncode = 0
148155
else:
149-
print(f"\nRunning Pyright regression tests for Python {_PYTHON_VERSION}...")
156+
print(f"\nRunning Pyright regression tests for Python {python_version}...")
150157
command = [
151158
sys.executable,
152159
"tests/pyright_test.py",
153160
str(test_cases_path),
154161
"--pythonversion",
155-
_PYTHON_VERSION,
162+
python_version,
156163
"-p",
157164
_TESTCASES_CONFIG_FILE,
158165
]
@@ -166,9 +173,9 @@ def main() -> None:
166173
pyright_testcases_returncode = pyright_testcases_result.returncode
167174
pyright_testcases_skipped = False
168175

169-
print(f"\nRunning mypy regression tests for Python {_PYTHON_VERSION}...")
176+
print(f"\nRunning mypy regression tests for Python {python_version}...")
170177
regr_test_result = subprocess.run(
171-
[sys.executable, "tests/regr_test.py", "stdlib" if folder == "stdlib" else stub, "--python-version", _PYTHON_VERSION],
178+
[sys.executable, "tests/regr_test.py", "stdlib" if folder == "stdlib" else stub, "--python-version", python_version],
172179
stderr=subprocess.PIPE,
173180
text=True,
174181
)

0 commit comments

Comments
 (0)