Search code examples
pythonpython-nose

The six module is causing problems with test coverage using nosetests


I'm using nosetests and the coverage extension to measure the coverage of my unit tests.

I've recently moved to including the six module with my package to make it easier for users.

The problem is that having six locally seems to mess up the coverage report.

I run my tests like this:

nosetests --cover-erase --with-coverage --cover-html --cover-package seaborn

The report ends up including references to files that aren't in my directory tree:

Name                    Stmts   Miss  Cover   Missing
-----------------------------------------------------
ConfigParser              391    391     0%   90-753
HTMLParser                306    306     0%   11-472
Queue                     125    125     0%   3-244
copy_reg                  105    105     0%   7-188
htmlentitydefs              9      9     0%   4-273
httplib                   704    704     0%   69-1342
repr                      103    103     0%   3-132
seaborn                     9      0   100%
<...>

The reason I think six is causing the problem is that when I search for those names, they only appear in six.py:

$ git grep ConfigParser
seaborn/external/six.py:    MovedModule("configparser", "ConfigParser"),

$ git grep copy_reg
seaborn/external/six.py:    MovedModule("copyreg", "copy_reg"),

At no point in my code do I import * from six, all of my imports are specific, like from .external.six.moves import range

How can I exclude these objects/files from the coverage report?

I've tried adding omit = seaborn/external to my .coveragerc (under [run]), and that excludes the files in seaborn/external from the report, but not the names that six seems to be defining.


Solution

  • Put this into your .coveragerc instead.

    [run]
    include = seaborn/*
    

    Documentation for configuration - http://nedbatchelder.com/code/coverage/config.html#config