Speed Up Coverage with Configuration File

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

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

Related Resources

Split Screen Without Tabs
Get your code and tests side-by-side without resorting to tabs.
Spot Coverage Gaps Using the Gutter
Let the IDE help you spot coverage gaps in your testing.
Auto-Run Tests
Get into testing mode by telling PyCharm to automatically re-run tests as you type.