From c43130cd9d2463049cef809be8c8d8404e355b92 Mon Sep 17 00:00:00 2001 From: AlexWaygood Date: Sat, 28 May 2022 15:42:22 +0100 Subject: [PATCH 1/4] CONTRIBUTING.md: improve docs for running tests (especially on Windows) --- CONTRIBUTING.md | 46 ++++++++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index eafefe346d01..95895379c109 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -17,36 +17,53 @@ 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 command isn't necessary if you're on Windows ``` ### Running tests -Once setup, you should be able to run tests: +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. + +However, if you wish to do so, you can run the full test suite +like this: ``` python3 runtests.py ``` -To use mypy to check mypy's own code, run: +Some magic incantations for running 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 -n0 mypy/test/testcheck.py::TypeCheckSuite::check-dataclasses.test + +# Run the linter +flake8 ``` You can also use `tox` to run tests, for instance: @@ -54,11 +71,8 @@ You can also use `tox` to run tests, for instance: tox -e py ``` -The easiest way to run a single test is: -``` -pytest -n0 -k 'test_name' -``` -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 From 678b01ee1aaea29eb46edb43d46e3a7a5b271b82 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Sun, 29 May 2022 00:10:25 +0100 Subject: [PATCH 2/4] Partially address review Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com> --- CONTRIBUTING.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 95895379c109..c16e92d6c8bc 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -35,7 +35,7 @@ source venv/bin/activate ``` python3 -m pip install -r test-requirements.txt python3 -m pip install -e . -hash -r # This command isn't necessary if you're on Windows +hash -r # This resets shell PATH cache, not necessary on Windows ``` ### Running tests @@ -51,7 +51,7 @@ like this: python3 runtests.py ``` -Some magic incantations for running tests include: +Some useful commands for running specific tests include: ``` # Use mypy to check mypy's own code python3 runtests.py self @@ -60,7 +60,7 @@ python3 runtests.py self pytest -n0 -k 'test_name' # Run all test cases in the "test-data/unit/check-dataclasses.test" file -pytest -n0 mypy/test/testcheck.py::TypeCheckSuite::check-dataclasses.test +pytest mypy/test/testcheck.py::TypeCheckSuite::check-dataclasses.test # Run the linter flake8 From 86ad47f9d62a166c2ae31570dea9dc2f7af0d423 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Sun, 29 May 2022 00:16:32 +0100 Subject: [PATCH 3/4] Finish addressing review --- CONTRIBUTING.md | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c16e92d6c8bc..40836cb75d98 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -51,10 +51,18 @@ like this: python3 runtests.py ``` +Mypy uses `pytest` as its test runner, but `tox` can also be used to run tests, +for instance: +``` +tox -e py +``` + 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' @@ -66,11 +74,6 @@ pytest mypy/test/testcheck.py::TypeCheckSuite::check-dataclasses.test flake8 ``` -You can also use `tox` to run tests, for instance: -``` -tox -e py -``` - For an in-depth guide on running and writing tests, see [the README in the test-data directory](test-data/unit/README.md). From e5bced87ada98a17767e7f7635643e2d7bb65069 Mon Sep 17 00:00:00 2001 From: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Date: Sat, 28 May 2022 16:56:17 -0700 Subject: [PATCH 4/4] Update CONTRIBUTING.md --- CONTRIBUTING.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 40836cb75d98..c51e812c6492 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -51,8 +51,7 @@ like this: python3 runtests.py ``` -Mypy uses `pytest` as its test runner, but `tox` can also be used 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 ```