Skip to content

Commit 500457a

Browse files
authored
Not to Tox (#1542)
1 parent 8b5d5c4 commit 500457a

File tree

2 files changed

+41
-41
lines changed

2 files changed

+41
-41
lines changed

docs/config_entries_config_flow_handler.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,4 +322,4 @@ Automated tests should verify that the reauth flow updates the existing config e
322322

323323
## Testing your config flow
324324

325-
Integrations with a config flow require full test coverage of all code in `config_flow.py` to be accepted into core. [Test your code](development_testing.md#testing-outside-of-tox) includes more details on how to generate a coverage report.
325+
Integrations with a config flow require full test coverage of all code in `config_flow.py` to be accepted into core. [Test your code](development_testing.md#running-a-limited-test-suite) includes more details on how to generate a coverage report.

docs/development_testing.md

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,18 @@ As it states in the [Style guidelines section](development_guidelines.md) all co
77
- All the unit tests pass
88
- All code passes the checks from the linting tools
99

10-
Local testing is done using [Tox](https://tox.readthedocs.io), which has been installed as part of running `script/setup` in the [virtual environment](development_environment.mdx). To start the tests, activate the virtual environment and simply run the command:
10+
Local testing is done using [pytest](https://docs.pytest.org/) and using [pre-commit](https://pre-commit.com/) for running out linters, which has been installed as part of running `script/setup` in the [virtual environment](development_environment.mdx).
11+
12+
To run our linters, on the full code base, run the following command:
13+
14+
```shell
15+
pre-commit run --all-files
16+
```
17+
18+
To start the tests, and run the full test suite, activate the virtual environment and run the command:
1119

1220
```shell
13-
tox
21+
pytest tests
1422
```
1523

1624
It might be required that you install additional packages depending on your distribution/operating system:
@@ -19,62 +27,45 @@ It might be required that you install additional packages depending on your dist
1927
- Ubuntu: `sudo apt-get install libudev-dev`
2028

2129
:::info Important
22-
Run `tox` before you create your pull request to avoid annoying fixes.
30+
Run `pytest` & `pre-commit` before you create your pull request to avoid annoying fixes.
31+
`pre-commit` will will be invoked automatically by git when commiting changes.
2332
:::
2433

2534
:::note
26-
Running the full `tox` test suite will take quite some time, so as the minimal requirement for pull requests, run at least the tests that are related to your code changes (see details below on how to). The full test suite will anyway be run by the CI once you created your pull request and before it can be merged.
35+
Running the full `ptyest` test suite will take quite some time, so as the minimal requirement for pull requests, run at least the tests that are related to your code changes (see details below on how to). The full test suite will anyway be run by the CI once you created your pull request and before it can be merged.
2736
:::
2837

29-
Running `tox` will run unit tests against the locally available Python releases, as well as validate the code and document style using `pycodestyle`, `pydocstyle` and `pylint`. You can run tests on only one `tox` target -- just use `-e` to select an environment. For example, `tox -e lint` runs the linters only, and `tox -e py39` runs unit tests only on Python 3.9.
30-
31-
`tox` uses virtual environments under the hood to create isolated testing environments. The `tox` virtual environments will get out-of-date when requirements change, causing test errors. Run `tox -r` to tell `tox` to recreate the virtual environments.
32-
33-
macOS users may see an `Error creating virtualenv` when running `tox`. If this occurs, install the [tox-venv](https://pypi.org/project/tox-venv/) package using the command `pip install tox-venv` and try again.
38+
Running `pytest` will run unit tests against the locally available Python version. We run our tests in our CI against all our supported Python versions.
3439

3540
### Adding new dependencies to test environment
3641

37-
If you are working on tests for an integration and you need the dependencies available inside the `tox` environment, update the list inside `script/gen_requirements_all.py`. Then run the script and then run `tox -r` to recreate the virtual environments.
38-
39-
### Running single tests using `tox`
40-
41-
You can pass arguments via `tox` to `pytest` to be able to run single test suites or test files. Replace `py39` with the Python version that you use.
42-
43-
```shell
44-
# Stop after the first test fails
45-
$ tox -e py39 -- tests/test_core.py -x
46-
# Run test with specified name
47-
$ tox -e py39 -- tests/test_core.py -k test_split_entity_id
48-
# Fail a test after it runs for 2 seconds
49-
$ tox -e py39 -- tests/test_core.py --timeout 2
50-
# Show the 10 slowest tests
51-
$ tox -e py39 -- tests/test_core.py --duration=10
52-
```
53-
54-
### Testing outside of Tox
55-
56-
Running `tox` will invoke the full test suite. Even if you specify which tox target to run, you still run all tests inside that target. That's not very convenient to quickly iterate on your code! To be able to run the specific test suites without `tox`, you'll need to install the test dependencies into your Python environment:
42+
If you are working on tests for an integration and you changed the dependencies, then run the `script/gen_requirements_all.py` script to update all requirement files.
43+
Next you can update all dependencies in your development environment by running:
5744

5845
```shell
5946
pip3 install --use-deprecated=legacy-resolver -r requirements_test_all.txt -c homeassistant/package_constraints.txt
6047
```
48+
### Running a limited test suite
6149

62-
Now that you have all test dependencies installed, you can run tests on individual files:
50+
You can pass arguments to `pytest` to be able to run single test suites or test files.
51+
Here are some helpful commands:
6352

6453
```shell
65-
flake8 homeassistant/core.py
66-
pylint homeassistant/core.py
67-
pydocstyle homeassistant/core.py
68-
pytest tests/test_core.py
69-
```
54+
# Stop after the first test fails
55+
$ pytest tests/test_core.py -x
7056

71-
You can also run linting tests against all changed files, as reported by `git diff upstream/dev... --diff-filter=d --name-only`, using the `lint` script:
57+
# Run test with specified name
58+
$ pytest tests/test_core.py -k test_split_entity_id
7259

73-
```shell
74-
script/lint
60+
# Fail a test after it runs for 2 seconds
61+
$ pytest tests/test_core.py --timeout 2
62+
63+
# Show the 10 slowest tests
64+
$ pytest tests/test_core.py --duration=10
7565
```
7666

77-
In case you want to check the code coverage for your new component, run the following from the root of the repository:
67+
If you want to test just your integration, and include a test coverage report,
68+
the following command is recommended:
7869

7970
```shell
8071
pytest ./tests/components/<your_component>/ --cov=homeassistant.components.<your_component> --cov-report term-missing -vv
@@ -84,12 +75,21 @@ pytest ./tests/components/<your_component>/ --cov=homeassistant.components.<your
8475

8576
Several linters are setup to run automatically when you try to commit as part of running `script/setup` in the [virtual environment](development_environment.mdx).
8677

87-
You can also run these linters manually:
78+
You can also run these linters manually :
8879

8980
```shell
9081
pre-commit run --show-diff-on-failure
9182
```
9283

84+
The linters are also available directly, you can run tests on individual files:
85+
86+
```shell
87+
flake8 homeassistant/core.py
88+
pylint homeassistant/core.py
89+
black homeassistant/core.py
90+
isort homeassistant/core.py
91+
```
92+
9393
### Notes on PyLint and PEP8 validation
9494

9595
If you can't avoid a PyLint warning, add a comment to disable the PyLint check for that line with `# pylint: disable=YOUR-ERROR-NAME`. Example of an unavoidable one is if PyLint incorrectly reports that a certain object doesn't have a certain member.

0 commit comments

Comments
 (0)