Skip to content

Commit fe8ca3b

Browse files
Add the capacity to run individual tests and test files to runtests.py (#19069)
I have added the capacity to run individual tests and files by specifying them to runtests.py, removing the burden of remembering the correct arguments to pytest. I have updated the contributor documentation accordingly.
1 parent c6c6e41 commit fe8ca3b

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

CONTRIBUTING.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,14 @@ python runtests.py self
7676
# or equivalently:
7777
python -m mypy --config-file mypy_self_check.ini -p mypy
7878

79-
# Run a single test from the test suite
80-
pytest -n0 -k 'test_name'
79+
# Run a single test from the test suite (uses pytest substring expression matching)
80+
python runtests.py test_name
81+
# or equivalently:
82+
pytest -n0 -k test_name
8183

8284
# Run all test cases in the "test-data/unit/check-dataclasses.test" file
85+
python runtests.py check-dataclasses.test
86+
# or equivalently:
8387
pytest mypy/test/testcheck.py::TypeCheckSuite::check-dataclasses.test
8488

8589
# Run the formatters and linters

runtests.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,13 @@
111111

112112
def run_cmd(name: str) -> int:
113113
status = 0
114-
cmd = cmds[name]
114+
if name in cmds:
115+
cmd = cmds[name]
116+
else:
117+
if name.endswith(".test"):
118+
cmd = ["pytest", f"mypy/test/testcheck.py::TypeCheckSuite::{name}"]
119+
else:
120+
cmd = ["pytest", "-n0", "-k", name]
115121
print(f"run {name}: {cmd}")
116122
proc = subprocess.run(cmd, stderr=subprocess.STDOUT)
117123
if proc.returncode:
@@ -144,13 +150,22 @@ def main() -> None:
144150
prog, *args = argv
145151

146152
if not set(args).issubset(cmds):
147-
print("usage:", prog, " ".join(f"[{k}]" for k in cmds))
153+
print(
154+
"usage:",
155+
prog,
156+
" ".join(f"[{k}]" for k in cmds),
157+
"[names of individual tests and files...]",
158+
)
148159
print()
149160
print(
150161
"Run the given tests. If given no arguments, run everything except"
151-
+ " pytest-extra and mypyc-extra."
162+
+ " pytest-extra and mypyc-extra. Unrecognized arguments will be"
163+
+ " interpreted as individual test names / substring expressions"
164+
+ " (or, if they end in .test, individual test files)"
165+
+ " and this script will try to run them."
152166
)
153-
exit(1)
167+
if "-h" in args or "--help" in args:
168+
exit(1)
154169

155170
if not args:
156171
args = DEFAULT_COMMANDS.copy()

0 commit comments

Comments
 (0)