Pytest plugin for excluding tests based on coverage data
Project description
Coverage-based test exclusion plugin for pytest. By looking at which lines are executed by each test, the next test run can be sped up by not executing the tests where no source files have changed.
If you have a large test suite which you often re-run, this plugin can drastically improve the iteration times.
Installation
Install with pip:
$ pip install pytest-cov-exclude
pytest-cov-exclude requires Pytest 2.8 or later. It is compatible with Python 2.7, 3.3, 3.4, 3.5, as well as PyPy. It does not work on PyPy 3 due to an unknown bug with the coverage data generated.
Usage
The first time you run your test suite, per-test coverage is enabled and the suite will take a little bit longer than usual:
$ py.test
==================== test session starts =====================
# Test output...
================ MANY passed in MANY seconds =================
Now when you re-run the test suite, all tests should have been excluded:
$ py.test
==================== test session starts =====================
# Test output...
=============== MANY deselected in FEW seconds ===============
If a test fails, it will re-run even if nothing changed in order to preserve the general failure status of the test suite.
Forcing individual test inclusion
If you have tests that depend on files not included in coverage data, such as data files or generated sources, you can mark the tests with external_dependencies. This forces them to be re-run even if no files were changed:
@pytest.mark.external_dependencies
def test_something():
# Run tests from external data files
Known bugs
Changes to files during pytest’s collection phase will be ignored. Test files and their dependencies are scanned as soon as possible after the test collection is complete.
There is a test case marked xfail that highlights this issue.
Running the whole test suite
If you want to force a complete re-run of the whole test suite, you have two options: either disable the plugin, or clear pytest’s cache:
$ py.test -p no:cov-exclude # Disable the plugin
$ py.test --cache-clear # Clear pytest's cache
Compatibility
As stated earlier, this plugin requires Pytest 2.8 or later since it depends on the new cache module.
While PyPy is supported, the ujson library used for faster serialization/deserialization is not available, so a fallback to the default JSON implementation is used instead. Because of this, the tests might actually run slower with this plugin under PyPy.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pytest-cov-exclude-0.0.8.tar.gz
.
File metadata
- Download URL: pytest-cov-exclude-0.0.8.tar.gz
- Upload date:
- Size: 7.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8fb1bb9dabedee650c1018eb6d05922ff94144248d2fb6f43c39aaf1c63a4697 |
|
MD5 | eb2ec5e2c9cd501159aa9a1e3b5e6a84 |
|
BLAKE2b-256 | f51b6eb5ef3632c5189468e6e536d022b96e7bb20cbaefdfb3af21c1d261432c |
File details
Details for the file pytest_cov_exclude-0.0.8-py2.py3-none-any.whl
.
File metadata
- Download URL: pytest_cov_exclude-0.0.8-py2.py3-none-any.whl
- Upload date:
- Size: 11.2 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3edb5a9941d58b38a9dbb5408a52411c6a424ded1cf819ace282893ca0ce7163 |
|
MD5 | 898ab78be3e2b16b80b49a2e88c2312f |
|
BLAKE2b-256 | 8d0c361873b29ea148c508d704c4a0bc65556751d07faa3cdedf03f50b8a6378 |