running nose --with-coverage to get all the package files, but not other dependencies and libs running nose --with-coverage to get all the package files, but not other dependencies and libs python python

running nose --with-coverage to get all the package files, but not other dependencies and libs


I had a very similar problem with generated code. The solution was to exclude the generated code or tools code in your case only from the reports.

So we now use nosetests to run our tests like

nosetests --with-coverage --cover-inclusive --cover-package=$(PACKAGE)

and afterwards, we create the reports manually, so

coverage combinecoverage report --omit 'tools/*'

Thus, coverage.py will cover your tools package, but they won't show up in the reports.


my tests/nose_setup_coverage.cfg file:

[nosetests]verbosity=1detailed-errors=1with-coverage=1cover-html=1cover-html-dir=../../out/cover#this is the line that fixed my equivalent of your issue#by "climbing up" from tests/ but skipping python's **site-packages**cover-package=..   where=/Users/jluc/kds2/py/tests

adding cover-package=.. (in the cfg file) and executing from within the tests directory got me to cover all my python directories, but not django and other 3rd party stuff.

This is my directory structure (minus some non-Python stuff):

.├── lib├── non_app├── ps_catalog├── pssecurity├── pssystem├── static├── static_src├── staticfiles├── templates├── tests└── websec

last, though it doesn't seem documented, coverage, as run from nosetests, will pick and use a .coveragerc file in the current (test) directory (you can't pass it via commandline or in the nose cfg file, that's for the cover plugin).

In that file, the omit section allows you finer control on which directories to exclude:

omit=/Users/jluc/kds2/env/lib/python2.7/*     */batch/*     /Users/jluc/kds2/py/non_app/*     */migrations/*

executing the tests in bash:

nosetests -c nose_setup_coverage.cfg

p.s. adding --cover-erase to the above, resets coverage

edit, FWIW:

I've generally replaced nose/nose2 with pytest as a test runner. If you don't bring in advanced pytest functionality, it will work just fine with plain old unittests and has a lot more plugins, support and active development. This is not to diss nose, or to promote pytest, but just saying that's an alternative to consider if you are repeatedly hitting edge cases with nose.


By default tests will not be included in the coverage report. You can make them show up (actually a very good idea to make sure your tests are properly executed, and no duplicate name tests are being ignored) with --cover-tests

In any case, nosetests --help is your friend. Most likely --cover-inclusive flag kills off coverage plugin and other options (for the plugin) become unavailable. You can try to debug it by launching nose through pdb.

As alternative you can run coverage as a standalone module launching nose tests.