Skip to content

Commit c6b3211

Browse files
authored
Improve test-suite documentation (#7756)
- mypy_test and pyright no longer just test the stubs, they now also test other parts of typeshed as well. - pytype_test.py can now be run on 3.10, meaning the whole test suite can now also be run on 3.10. - Various test scripts now have from `__future__ import annotations`, meaning they can now only be run on 3.7+. - Clean up the description of pyright_test.py, which had a slightly confusing wording. - Also fix the `--dry-run` config option in mypy_test.py, which I accidentally broke in #7746
1 parent e8e74ba commit c6b3211

File tree

3 files changed

+30
-21
lines changed

3 files changed

+30
-21
lines changed

.github/workflows/tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050
- run: ./tests/pytype_test.py --print-stderr
5151

5252
mypy:
53-
name: Run mypy against the stubs
53+
name: Run mypy against typeshed
5454
runs-on: ubuntu-latest
5555
strategy:
5656
matrix:
@@ -64,7 +64,7 @@ jobs:
6464
- run: ./tests/mypy_test.py --platform=${{ matrix.platform }} --python-version=${{ matrix.python-version }}
6565

6666
pyright:
67-
name: Run pyright against the stubs
67+
name: Run pyright against typeshed
6868
runs-on: ubuntu-latest
6969
strategy:
7070
matrix:

tests/README.md

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,31 @@ objects at runtime.
1313
objects at runtime.
1414

1515
To run the tests, follow the [setup instructions](../CONTRIBUTING.md#preparing-the-environment)
16-
in the `CONTRIBUTING.md` document. In particular, we recommend running with Python 3.8 or 3.9.
16+
in the `CONTRIBUTING.md` document. In particular, we recommend running with Python 3.8+.
1717

1818
## mypy\_test.py
1919

20-
This test requires Python 3.6 or higher; Python 3.6.1 or higher is recommended.
21-
Run using:
20+
This test requires Python 3.7+. Run using:
2221
```
2322
(.venv3)$ python3 tests/mypy_test.py
2423
```
2524

26-
This test is shallow — it verifies that all stubs can be
25+
The test has four parts. Each part uses mypy with slightly different configuration options:
26+
- Running mypy on the stdlib stubs
27+
- Running mypy on the third-party stubs
28+
- Running mypy `--strict` on the scripts in the `tests` directory
29+
- Running mypy `--strict` on the regression tests in the `test_cases` directory.
30+
31+
When running mypy on the stubs, this test is shallow — it verifies that all stubs can be
2732
imported but doesn't check whether stubs match their implementation
28-
(in the Python standard library or a third-party package). It has an exclude list of
29-
modules that are not tested at all, which also lives in the tests directory.
33+
(in the Python standard library or a third-party package).
3034

31-
You can restrict mypy tests to a single version by passing `-p2` or `-p3.9`:
32-
```bash
33-
(.venv3)$ python3 tests/mypy_test.py -p3.9
34-
```
35+
Run `python tests/mypy_test.py --help` for information on the various configuration options
36+
for this test script.
3537

3638
## pytype\_test.py
3739

38-
This test requires Python between 3.6 and 3.9.
40+
This test requires Python 3.7+.
3941
Note: this test cannot be run on Windows
4042
systems unless you are using Windows Subsystem for Linux.
4143

@@ -48,18 +50,19 @@ This test works similarly to `mypy_test.py`, except it uses `pytype`.
4850

4951
## pyright\_test.py
5052

51-
This test requires [Node.js](https://nodejs.org) to be installed. It is
52-
currently not part of the CI,
53-
but it uses the same pyright version and configuration as the CI.
53+
This test requires [Node.js](https://nodejs.org) to be installed. Although
54+
typeshed runs pyright in CI, it does not currently use this script. However,
55+
this script uses the same pyright version and configuration as the CI.
5456
```
5557
(.venv3)$ python3 tests/pyright_test.py # Check all files
5658
(.venv3)$ python3 tests/pyright_test.py stdlib/sys.pyi # Check one file
5759
(.venv3)$ python3 tests/pyright_test.py -p pyrightconfig.stricter.json # Check with the stricter config.
5860
```
5961

6062
`pyrightconfig.stricter.json` is a stricter configuration that enables additional
61-
checks that would typically fail on incomplete stubs (such as `Unknown` checks),
62-
and is run on a subset of stubs (including the standard library).
63+
checks that would typically fail on incomplete stubs (such as `Unknown` checks).
64+
In typeshed's CI, pyright is run with these configuration settings on a subset of
65+
the stubs in typeshed (including the standard library).
6366

6467
## check\_consistent.py
6568

@@ -102,7 +105,7 @@ stubtest can also help you find things missing from the stubs.
102105

103106
## stubtest\_third\_party.py
104107

105-
This test requires Python 3.6 or higher.
108+
This test requires Python 3.7+.
106109
Run using
107110
```
108111
(.venv3)$ python3 tests/stubtest_third_party.py

tests/mypy_test.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,10 @@ def test_the_test_scripts(code: int, major: int, minor: int, args: argparse.Name
358358
flags = get_mypy_flags(args, major, minor, None, strict=True, test_suite_run=True)
359359
print(f"Testing the test suite ({num_test_files_to_test} files)...")
360360
print("Running mypy " + " ".join(flags))
361-
this_code = subprocess.run([sys.executable, "-m", "mypy", "tests", *flags]).returncode
361+
if args.dry_run:
362+
this_code = 0
363+
else:
364+
this_code = subprocess.run([sys.executable, "-m", "mypy", "tests", *flags]).returncode
362365
code = max(code, this_code)
363366
return TestResults(code, num_test_files_to_test)
364367

@@ -369,7 +372,10 @@ def test_the_test_cases(code: int, major: int, minor: int, args: argparse.Namesp
369372
flags = get_mypy_flags(args, major, minor, None, strict=True, custom_typeshed=True)
370373
print(f"Running mypy on the test_cases directory ({num_test_case_files} files)...")
371374
print("Running mypy " + " ".join(flags))
372-
this_code = subprocess.run([sys.executable, "-m", "mypy", "test_cases", *flags]).returncode
375+
if args.dry_run:
376+
this_code = 0
377+
else:
378+
this_code = subprocess.run([sys.executable, "-m", "mypy", "test_cases", *flags]).returncode
373379
code = max(code, this_code)
374380
return TestResults(code, num_test_case_files)
375381

0 commit comments

Comments
 (0)