From 76f3acce0723940c50b98c95deaa3c96e25d7f55 Mon Sep 17 00:00:00 2001 From: wyattscarpenter Date: Sat, 10 May 2025 02:43:18 -0700 Subject: [PATCH 1/2] runtests.py can now run individual files and tests --- runtests.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/runtests.py b/runtests.py index 75389c6c56bb..5139f8934e3e 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,21 @@ 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 (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() From e9fdde3e18aec3f8e14f7f5868d84851111548eb Mon Sep 17 00:00:00 2001 From: wyattscarpenter Date: Sat, 10 May 2025 02:56:33 -0700 Subject: [PATCH 2/2] update contributing.md with new commands and learn about pytest substring expressions --- CONTRIBUTING.md | 8 ++++++-- runtests.py | 5 +++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e782158ba21f..8d7dd2d1e886 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 5139f8934e3e..3f49107f3ce0 100755 --- a/runtests.py +++ b/runtests.py @@ -160,8 +160,9 @@ def main() -> None: print( "Run the given tests. If given no arguments, run everything except" + " pytest-extra and mypyc-extra. Unrecognized arguments will be" - + " interpreted as individual test names (or, if they end in .test," - + " individual test files) and this script will try to run them." + + " interpreted as individual test names / substring expressions" + + " (or, if they end in .test, individual test files)" + + " and this script will try to run them." ) if "-h" in args or "--help" in args: exit(1)