Skip to content

CONTRIBUTING.md: improve docs for running tests (especially on Windows) #12898

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 29, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 34 additions & 18 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,48 +17,64 @@ articulated in the [Python Community Code of Conduct](https://www.python.org/psf

### Setup

Run the following:
#### (1) Clone the mypy repository and enter into it
```
# Clone the mypy repository
git clone https://github.com/python/mypy.git

# Enter the repository
cd mypy
```

# Create then activate a virtual environment
#### (2) Create then activate a virtual environment
```
# On Windows, the commands may be slightly different. For more details, see
# https://docs.python.org/3/library/venv.html#creating-virtual-environments
python3 -m venv venv
source venv/bin/activate
```

# Install the test requirements and the project
#### (3) Install the test requirements and the project
```
python3 -m pip install -r test-requirements.txt
python3 -m pip install -e .
hash -r
hash -r # This resets shell PATH cache, not necessary on Windows
```

### Running tests

Once setup, you should be able to run tests:
```
python3 runtests.py
```
Running the full test suite can take a while, and usually isn't necessary when
preparing a PR. Once you file a PR, the full test suite will run on GitHub.
You'll then be able to see any test failures, and make any necessary changes to
your PR.

To use mypy to check mypy's own code, run:
However, if you wish to do so, you can run the full test suite
like this:
```
python3 runtests.py self
# or equivalently:
python3 -m mypy --config-file mypy_self_check.ini -p mypy
python3 runtests.py
```

You can also use `tox` to run tests, for instance:
You can also use `tox` to run tests (`tox` handles setting up the test environment for you):
```
tox -e py
```

The easiest way to run a single test is:
Some useful commands for running specific tests include:
```
# Use mypy to check mypy's own code
python3 runtests.py self
# or equivalently:
python3 -m mypy --config-file mypy_self_check.ini -p mypy

# Run a single test from the test suite
pytest -n0 -k 'test_name'

# Run all test cases in the "test-data/unit/check-dataclasses.test" file
pytest mypy/test/testcheck.py::TypeCheckSuite::check-dataclasses.test

# Run the linter
flake8
```
There's more useful information on writing and running tests [here](test-data/unit/README.md)

For an in-depth guide on running and writing tests,
see [the README in the test-data directory](test-data/unit/README.md).

## First time contributors

Expand Down