Skip to main content

Pytest plugin to only run tests affected by changes

Project description

pytest-cagoule is a pytest plugin to find which tests interact with the code you’ve just changed.


Collect coverage information using --pytest-cov coverage contexts.

py.test --cov --cov-context=test

Then, to run the subset of tests that touch a particular file, use cagoule-select=<filename>[:line number], e.g.

py.test --cagoule-select=path/to/

If you are using git, cagoule can find the files and lines that have changes in the current working directory:

py.test --diff

or for any other diff spec that git can parse, using --diff=<spec>, e.g.

py.test --diff=head~1..head

You probably want to configure your CI server to handle capturing.


Install pytest-cagoule using pip:

pip install pytest-cagoule


Only lines executed during individual test runs are captured. This often excludes module level code, which is executed at import time, before the test starts. Also, tests are of course registered against the code as it was when data was captured, so if using --diff, no new tests will be included.


Idea from nose-knows


MIT. See LICENSE for details

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for pytest-cagoule, version 0.4.0
Filename, size File type Python version Upload date Hashes
Filename, size pytest-cagoule-0.4.0.tar.gz (5.4 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page