Allow adding test cases testing version-dependent Python features (#9238)

This commit is contained in:
Alex Waygood
2022-11-21 16:03:28 +00:00
committed by GitHub
parent c161827d6d
commit 1f8491d23d
2 changed files with 28 additions and 1 deletions

View File

@@ -93,3 +93,17 @@ extensions, and since the tests need to pass on all Python versions >=3.7, PEP
PEP 585 syntax can also not be used in the `test_cases` directory. Use
`typing.Tuple` instead of `tuple`, `typing.Callable` instead of
`collections.abc.Callable`, and `typing.Match` instead of `re.Match` (etc.).
### Version-dependent tests
Some tests will only pass on mypy
with a specific Python version passed on the command line to the `tests/regr_test.py` script.
To mark a test-case file as being skippable on lower versions of Python,
append `-py3*` to the filename.
For example, if `foo` is a stdlib feature that's new in Python 3.9,
test cases for `foo` should be put in a file named `test_cases/stdlib/check_foo-py39.py`.
This means that mypy will only run the test case
if `--python-version 3.9`, `--python-version 3.10` or `--python-version 3.11`
is passed on the command line to `tests/regr_test.py`,
but it *won't* run the test case if `--python-version 3.7` or `--python-version 3.8`
is passed on the command line.