diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e782158ba21f4..8d7dd2d1e886e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -76,10 +76,14 @@ python runtests.py self # or equivalently: python -m mypy --config-file mypy_self_check.ini -p mypy -# Run a single test from the test suite -pytest -n0 -k 'test_name' +# Run a single test from the test suite (uses pytest substring expression matching) +python runtests.py test_name +# or equivalently: +pytest -n0 -k test_name # Run all test cases in the "test-data/unit/check-dataclasses.test" file +python runtests.py check-dataclasses.test +# or equivalently: pytest mypy/test/testcheck.py::TypeCheckSuite::check-dataclasses.test # Run the formatters and linters diff --git a/runtests.py b/runtests.py index 75389c6c56bb0..3f49107f3ce05 100755 --- a/runtests.py +++ b/runtests.py @@ -111,7 +111,13 @@ def run_cmd(name: str) -> int: status = 0 - cmd = cmds[name] + if name in cmds: + cmd = cmds[name] + else: + if name.endswith(".test"): + cmd = ["pytest", f"mypy/test/testcheck.py::TypeCheckSuite::{name}"] + else: + cmd = ["pytest", "-n0", "-k", name] print(f"run {name}: {cmd}") proc = subprocess.run(cmd, stderr=subprocess.STDOUT) if proc.returncode: @@ -144,13 +150,22 @@ def main() -> None: prog, *args = argv if not set(args).issubset(cmds): - print("usage:", prog, " ".join(f"[{k}]" for k in cmds)) + print( + "usage:", + prog, + " ".join(f"[{k}]" for k in cmds), + "[names of individual tests and files...]", + ) print() print( "Run the given tests. If given no arguments, run everything except" - + " pytest-extra and mypyc-extra." + + " pytest-extra and mypyc-extra. Unrecognized arguments will be" + + " interpreted as individual test names / substring expressions" + + " (or, if they end in .test, individual test files)" + + " and this script will try to run them." ) - exit(1) + if "-h" in args or "--help" in args: + exit(1) if not args: args = DEFAULT_COMMANDS.copy()