pythoncode-coveragenosepython-coverage

Generate html report from .coverage file


I'm looking for a way to combine multiple .coverage files and then generate an html report. Currently I'm generating coverage just from one source with the following command and it works fine:

nosetests --with-coverage --cover-erase --cover-html --cover-html-dir=/var/www/coverage

Now I want to start by splitting the process in two:

  1. Generate coverage report (.coverage file)
  2. Generate html report from .coverage file

First step is clear, same command as before ommiting the html part. Then I've seen in many places to just run coverage html, including python coverage package website. When I do that I obtain a console-printed report of my coverage and the following

======================================================================
ERROR: Failure: ImportError (No module named html)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/nose/loader.py", line 402, in loadTestsFromName
    module = resolve_name(addr.module)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/nose/util.py", line 311, in resolve_name
    module = __import__('.'.join(parts_copy))
ImportError: No module named html

It's like nose is interfering somehow:

$ coverage report -m
Usage: nosetests [options]

nosetests: error: -m option requires an argument

$ coverage --help
Usage: nosetests [options]

Solution

  • Looks like your coverage package is not installed properly. Try running pip freeze to see if you have a standalone coverage==3.5.3 or equivalent installed. If you do not have anything, try pip install coverage. Once installed you will have access to coverage binary in python binary utilities folder, rather what looks like nosetests alias.