@@ -86,24 +86,22 @@ requests. If you have questions related to contributing, drop by the [typing Git
8686## Running the tests
8787
8888The tests are automatically run by Travis CI on every PR and push to
89- the repo. There are several sets of tests: ` tests/mypy_test.py `
90- runs tests against [ mypy] ( https://github.com/python/mypy/ ) , while
91- ` tests/pytype_test.py ` runs tests against
92- [ pytype] ( https://github.com/google/pytype/ ) .
93-
94- Both sets of tests are shallow -- they verify that all stubs can be
95- imported but they don't check whether stubs match their implementation
96- (in the Python standard library or a third-party package). Also note
97- that each set of tests has a blacklist of modules that are not tested
98- at all. The blacklists also live in the tests directory.
89+ the repo. Note that it can be useful to enable Travis CI on your own fork of
90+ typeshed.
9991
100- In addition, you can run ` tests/mypy_selftest.py ` to run mypy's own
101- test suite using the typeshed code in your repo. This will sometimes
102- catch issues with incorrectly typed stubs, but is much slower than the
103- other tests.
92+ There are several tests:
93+ - ` tests/mypy_test.py `
94+ runs tests against [ mypy] ( https://github.com/python/mypy/ )
95+ - ` tests/pytype_test.py ` runs tests against
96+ [ pytype] ( https://github.com/google/pytype/ ) .
97+ - ` tests/mypy_selftest.py ` runs mypy's test suite using this version of
98+ typeshed.
99+ - ` tests/check_consistent.py ` checks certain files in typeshed remain
100+ consistent with each other.
101+ - ` tests/stubtest_test.py ` checks stubs against the objects at runtime.
102+ - ` flake8 ` enforces a style guide.
104103
105- To manually run the mypy tests, you need to have Python 3.5 or higher;
106- Python 3.6.1 or higher is recommended.
104+ ### Setup
107105
108106Run:
109107```
@@ -112,31 +110,74 @@ $ source .venv3/bin/activate
112110(.venv3)$ pip3 install -r requirements-tests-py3.txt
113111```
114112This will install mypy (you need the latest master branch from GitHub),
115- typed-ast, flake8, and pytype. You can then run mypy, flake8, and pytype tests
116- by invoking:
117- ```
118- (.venv3)$ python3 tests/mypy_test.py
119- ...
120- (.venv3)$ python3 tests/mypy_selftest.py
121- ...
122- (.venv3)$ flake8
123- ...
124- (.venv3)$ python3 tests/pytype_test.py
125- ...
126- ```
127- Note that flake8 only works with Python 3.6 or higher, and that to run the
128- pytype tests, you will need Python 2.7 and Python 3.6 interpreters. Pytype will
129- find these automatically if they're in ` PATH ` , but otherwise you must point to
130- them with the ` --python27-exe ` and ` --python36-exe ` arguments, respectively.
113+ typed-ast, flake8 (and plugins), pytype, black and isort.
114+
115+ ### mypy_test.py
131116
132- For mypy, if you are in the typeshed repo that is submodule of the
117+ This test requires Python 3.5 or higher; Python 3.6.1 or higher is recommended.
118+ Run using:` (.venv3)$ python3 tests/mypy_test.py `
119+
120+ This test is shallow — it verifies that all stubs can be
121+ imported but doesn't check whether stubs match their implementation
122+ (in the Python standard library or a third-party package). It has a blacklist of
123+ modules that are not tested at all, which also lives in the tests directory.
124+
125+ If you are in the typeshed repo that is submodule of the
133126mypy repo (so ` .. ` refers to the mypy repo), there's a shortcut to run
134127the mypy tests that avoids installing mypy:
135128``` bash
136129$ PYTHONPATH=../.. python3 tests/mypy_test.py
137130```
138- You can mypy tests to a single version by passing ` -p2 ` or ` -p3.5 ` e.g.
131+ You can restrict mypy tests to a single version by passing ` -p2 ` or ` -p3.5 ` :
139132``` bash
140133$ PYTHONPATH=../.. python3 tests/mypy_test.py -p3.5
141134running mypy --python-version 3.5 --strict-optional # with 342 files
142135```
136+
137+ ### pytype_test.py
138+
139+ This test requires Python 2.7 and Python 3.6. Pytype will
140+ find these automatically if they're in ` PATH ` , but otherwise you must point to
141+ them with the ` --python27-exe ` and ` --python36-exe ` arguments, respectively.
142+ Run using: ` (.venv3)$ python3 tests/pytype_test.py `
143+
144+ This test works similarly to ` mypy_test.py ` , except it uses ` pytype ` .
145+
146+ ### mypy_selftest.py
147+
148+ This test requires Python 3.5 or higher; Python 3.6.1 or higher is recommended.
149+ Run using: ` (.venv3)$ python3 tests/mypy_selftest.py `
150+
151+ This test runs mypy's own test suite using the typeshed code in your repo. This
152+ will sometimes catch issues with incorrectly typed stubs, but is much slower
153+ than the other tests.
154+
155+ ### check_consistent.py
156+
157+ Run using: ` python3 tests/check_consistent.py `
158+
159+ ### stubtest_test.py
160+
161+ This test requires Python 3.5 or higher.
162+ Run using ` (.venv3)$ python3 tests/stubtest_test.py `
163+
164+ This test compares the stdlib stubs against the objects at runtime. Because of
165+ this, the output depends on which version of Python it is run with.
166+ If you need a specific version of Python to repro a CI failure,
167+ [ pyenv] ( https://github.com/pyenv/pyenv ) can help (as can enabling Travis CI on
168+ your fork).
169+
170+ Due to its dynamic nature, you may run into false positives. In this case, you
171+ can add to the whitelists for each affected Python version in
172+ ` tests/stubtest_whitelists ` . Please file issues for stubtest false positives
173+ at [ mypy] ( https://github.com/python/mypy/issues ) .
174+
175+ To run stubtest against third party stubs, it's easiest to use stubtest
176+ directly. stubtest can also help you find things missing from the stubs.
177+
178+
179+ ### flake8
180+
181+ flake8 requires Python 3.6 or higher. Run using: ` (.venv3)$ flake8 `
182+
183+ Note typeshed uses the ` flake8-pyi ` and ` flake8-bugbear ` plugins.
0 commit comments