wakelift / posts /


A few days ago I stumbled upon a blog post about a perl module that generates vim signs for line coverage in perl scripts, which was based off of SimpleCov from the Ruby world. It would generate a vimscript file that would set vim marks in files that were analysed for coverage.

Since I don't use Ruby nor perl5 (although I do dabble in perl6 every now and then), I thought I could port it to Ned Batchelder's coverage.py. It turned out to be pretty simple, as coverage.py is rather well organised.

Thus, my little feature branch for vim sign output for coverage.py was born.

It might be very simple, but it does seem to work fine. Here is a screenshot of it in action:

It works like this:

# run the test suite with coverage enabled, thus creating the file .coverage
py.test --cov mymodule
# generate a vim-"report" of the coverage data
coverage vim
# then, in vim, source the coverage-data.vim file
:so coverage-data.vim

Whenever you open a new file, that's part of your coverage, you have to execute :Cov again to get the signs. When editing the files, vim will try to move the signs around, but you will have to recreate the coverage information manually from time to time.

There are things that could be done to make this more integrated with vim, but I think this'll do.

The next step is to see if I can get the code accepted in upstream coverage.py and get support for it into pytest-coverage, too.