insomnihack

When sleep eludes, the keyboard beckons

Run Coverage.py under PyCharm

July 18, 2010 Dale Leave a Comment

PyCharm‘s test runner does not currently support running Ned Batchelder’s excellent Python code coverage tool coverage.py. While this may be addressed before final release, you can easily set up a run/debug configuration manually to get the same effect. From within PyCharm, select the Run -> Edition Configurations menu item.

Coverage.py Configuration

Coverage.py Configuration

In the Run/Debug Configurations dialog, click the box with the plus sign in the upper right corner to create a new Python script configuration. Call the configuration whatever you want. I tend to run coverage.py as part of nose, so I enter the path to the nosetests-script.py on my file system in the Script field. Under Windows, this will be in the Scripts sub-directory of your Python installation directory. If you’re on Linux or OSX, you can use the nose/core.py file in your site-packages folder.

In the Script parameters field, I enter the --with-coverage and --cover-package command line parameters. Finally, in the Working directory field, I add the path to the directory containing my unit tests. Running this configuration executes code coverage on my unit test directory, and PyCharm is smart enough to recognize any stack traces that may occur during the run, providing click-able links to the offending lines of code.

Programming PyCharm, Python, tools, unit tests

Leave a Reply

Your email address will not be published. Required fields are marked *

About Me

Hi, my name's Dale, and this is my tech blog. Read More…

Search

Tags

blogging c# database Django documentation Email furniture git hacks htpc IPython Linux mac nas packaging PyCharm Python Roleplaying tools twitter unit tests virtualenv Visual Studio vmware Windows

Copyright © 2025 · Equilibre Theme on Genesis Framework · WordPress · Log in