SublimePythonCoverage is a plugin for Sublime Text 2
that can highlight lines of Python lacking test coverage,
based on the output of Ned Batchelder's
Set up Sublime Package Control if you don't have it yet.
Go to Tools > Command Palette.
Package Control: Install Package and hit enter.
Python Coverage and hit enter.
It may take a bit to install as it needs to fetch its dependency, coverage.py.
Highlighting lines missing coverage
When you open a .py file, SublimePythonCoverage tries to find coverage information and highlight all uncovered lines with an outline.
It does this by looking in all parent directories
until it finds a
.coverage file as produced by
Obviously, it only works if that file exists
and contains coverage information for the .py file you opened.
You can force a reload of the coverage information
and redraw of the outlines
by running the
bound to super+shift+c by default.
Running tests with coverage
Set your build system to either
Python Nose with Coverage
Python pytest with Coverage.
Now when you trigger a build in Sublime Text 2,
it will run
nosetests --with-coverage or
py.test to generate
coverage data, and then update the highlighted lines. In the
latter case, your setup.cfg or pytest.ini is expected to
provide the options necessary to test your package and generate
SublimePythonCoverage uses a simple heuristic
to guess the right
py.test script to run.
First it looks in all parent directories for
If that fails, it tries to find
py.test in the PATH.
SublimePythonCoverage uses another heuristic
to guess what path to pass to
If the directory of the current file is not a package,
(i.e., does not contain an
nosetests on the current file. This does not work for
Otherwise, it looks in all parent directories for
and if it finds it it starts the test runner on that directory.
If not, it runs the tests on the directory of the current file.