You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: source/developers/development_testing.markdown
+29-18Lines changed: 29 additions & 18 deletions
Original file line number
Diff line number
Diff line change
@@ -9,31 +9,28 @@ sharing: true
9
9
footer: true
10
10
---
11
11
12
-
As states in the [Style guidelines section](/developers/development_guidelines/) all code is checked as part of the linting process and unit test were run.
13
-
14
-
### {% linkable_title Local testing %}
15
-
16
-
**Important:** Run `tox` before you create your pull request to avoid annoying fixes. Local testing requires installing `tox`.
12
+
As states in the [Style guidelines section](/developers/development_guidelines/) all code is checked to verify all unit tests pass and that the code passes the linting tools. Local testing is done using Tox, which has been installed as part of running `script/setup`. To start the tests, simply run it:
17
13
18
14
```bash
19
-
$ pip3 install tox
15
+
$ tox
20
16
```
17
+
**Important:** Run `tox` before you create your pull request to avoid annoying fixes.
21
18
22
-
Start your code test with `tox`.
19
+
Running Tox will run unit tests against the locally available Pythons, 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 py34` runs unit tests only on Python 3.4.
23
20
24
-
```bash
25
-
$ tox
26
-
```
21
+
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.
27
22
28
-
This will run unit tests against Python 3.4 and 3.5 (if both are available locally), as well as tests that validate `pep8`and `pylint` style.
23
+
If you are working on tests for a component or platform 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.
29
24
30
-
####{% linkable_title Testing Tips %}
25
+
### {% linkable_title Testing single files %}
31
26
32
-
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 py34` runs unit tests only on Python 3.4.
27
+
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:
33
28
34
-
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 create new tox virtual environments.
29
+
```bash
30
+
$ bash pip3 install -r requirements_test_all.txt
31
+
```
35
32
36
-
During development on a specific file, speed up your workflow by running tests and linting only for the file that you're working on. To run individual files:
33
+
Now that you have all test dependencies installed, you can run tests on individual files:
37
34
38
35
```bash
39
36
$ flake8 homeassistant/core.py
@@ -48,8 +45,23 @@ You can also run linting tests against all changed files, as reported by `git di
48
45
$ script/lint --changed
49
46
```
50
47
48
+
#### {% linkable_title Py.test tips %}
49
+
50
+
Py.test has some great command line parameters to help you with the write-test-fix cycle.
Save yourself the hassle of extra commits just to fix style errors by enabling the Flake8 git commit hook. Flake8 will check your code when you try to commit to the repository and block the commit if there are any style errors, which gives you a chance to fix them!
54
66
55
67
```bash
@@ -61,5 +73,4 @@ The `flake8-docstrings` extension will check docstrings according to [PEP257](ht
61
73
62
74
### {% linkable_title Notes on PyLint and PEP8 validation %}
63
75
64
-
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`. An example of an unavoidable PyLint warning is not using the passed-in datetime if you're listening for a time change.
65
-
76
+
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