Testing
Run all tests
Running all tests should be as simple as this:
Run specific tests
Run only tests which have "foo" in the file or function name:
Watch tests
To automatically re-run tests while you are working on them, use
pytest-watcher
(q
to quit):
You can also watch specific tests using the -k
flag:
By default, tests are re-run 0.2 seconds after the last file edit. To increase the delay, pass --delay
:
Getting test coverage
Terminal
To see the test coverage, add --cov
to any of the above commands. For example, this will output the coverage report to the terminal:
HTML report
To see a browsable HTML report:
You can watch HTML coverage by running:
and openinghtmlcov/index.html
in your browser.
To watch coverage for a specific test:
The tests may "fail" because the tests matchingfoo
will be expected to provide coverage for the whole project. But you can open htmlcov/index.html
in your browser and browse to just the relevant file.