Speed Up Coverage with Configuration File

Speed up your "visual coverage" with a config file and correct working directory.

Coverage is good, fast coverage is better.

Python's coverage tool will by default measure in lots of places. Like your dependencies and tests. Speed up coverage reporting by restricting where coverage will look.

In Depth

Coverage is a boon: it lets you know how much of your code has tests and better, which lines in which files don't.

That comes at a price: instrumentation takes a while. You can speed up coverage by telling it to not look in places you don't care about: your virtual environment's dependencies, your project's tests directory itself, .tox directories, etc. You'll also get more accurate percentages.

This is done with a .coveragerc configuration file, which has lots of options.

PyCharm though is finicky about this, hence this tip:

  • Put your .coveragerc file in your project root

  • Make a run configuration to run your tests, and...

  • ...edit that run configuration's working directory to start at the root

Full Video