Skip to content

Commit 4b3a8a8

Browse files
authored
Improve support for running tests on Windows (#6284)
1 parent fecf258 commit 4b3a8a8

File tree

3 files changed

+47
-10
lines changed

3 files changed

+47
-10
lines changed

CONTRIBUTING.md

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,54 @@ it takes a bit longer. For more details, read below.
2525
## Preparing the environment
2626

2727
To reformat the code, check for common problems, and
28-
run the tests, you need to prepare a
29-
[virtual environment](https://docs.python.org/3/tutorial/venv.html)
30-
with the necessary libraries installed using Python 3.8 or newer.
28+
run the tests, it can be useful to prepare a
29+
[virtual environment](https://docs.python.org/3/tutorial/venv.html) and install
30+
certain libraries typeshed uses to check stub files.
31+
32+
Follow platform-specific instructions below. Following that, to automatically
33+
check your code before committing, you can copy the file `pre-commit` to
34+
`.git/hooks/pre-commit`.
35+
36+
### Linux/Mac OS
37+
38+
On Linux and Mac OS, you will be able to run the full test suite on Python 3.8
39+
or 3.9. Running the tests on <=3.7 is not supported, and the pytype tests
40+
[cannot currently be run on Python 3.10](https://github.com/google/pytype/issues/1022).
41+
42+
To install the necessary requirements, run the following commands from a
43+
terminal window:
3144

32-
To do this, run:
3345
```
3446
$ python3 -m venv .venv3
3547
$ source .venv3/bin/activate
3648
(.venv3)$ pip install -U pip
3749
(.venv3)$ pip install -r requirements-tests-py3.txt
3850
```
3951

40-
To automatically check your code before committing, copy the file
41-
`pre-commit` to `.git/hooks/pre-commit`.
52+
### Windows
53+
54+
If you are using a Windows operating system, you will not be able to run the
55+
full test suite. One option is to install
56+
[Windows Subsystem for Linux](https://docs.microsoft.com/en-us/windows/wsl/faq),
57+
which will allow you to run the full suite of tests. If you choose to install
58+
WSL, follow the Linux/Mac OS instructions above.
59+
60+
If you do not wish to install WSL, you will not be able to run the pytype
61+
tests, as pytype
62+
[does not currently support running on Windows](https://github.com/google/pytype#requirements).
63+
However, the upside of this is that you will be able to run all
64+
Windows-compatible tests on Python 3.9, 3.8 or 3.10, as it is only the pytype
65+
tests that cannot currently be run on 3.10.
66+
67+
To install all non-pytype requirements on Windows without WSL, run the
68+
following commands from a Windows terminal:
69+
70+
```
71+
> python3 -m venv .venv3
72+
> ".venv3/Scripts/activate"
73+
(.venv3) > python -m pip install -U pip
74+
(.venv3) > python -m pip install -r requirements-tests-py3.txt
75+
```
4276

4377
## Where to make changes
4478

requirements-tests-py3.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
mypy==0.910
2-
pytype==2021.11.2
2+
pytype==2021.11.2; platform_system != "Windows"
33
black==21.9b0
44
flake8==4.0.1
55
flake8-bugbear==21.9.2

tests/README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ 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 newer.
16+
in the `CONTRIBUTING.md` document. In particular, we recommend running with Python 3.8 or 3.9.
1717

1818
## mypy\_test.py
1919

@@ -35,8 +35,11 @@ You can restrict mypy tests to a single version by passing `-p2` or `-p3.9`:
3535

3636
## pytype\_test.py
3737

38-
This test requires Python 2.7 and Python 3.6. Pytype will
39-
find these automatically if they're in `PATH`.
38+
This test requires Python 2.7 and Python 3.6. Pytype will find these
39+
automatically if they're in `PATH`. Note: this test cannot be run on Windows
40+
systems unless you are using Windows Subsystem for Linux. Pytype also does not
41+
yet fully support Python 3.10.
42+
4043
Run using:
4144
```
4245
(.venv3)$ python3 tests/pytype_test.py

0 commit comments

Comments
 (0)