7

I'm using nosetests to run a few unit tests and show me our code coverage using something like:

nosetests -w ./test --with-xunit --with-coverage --cover-tests

This works well except for the fact that I'm seeing a bunch of Python packages in the output. Here's a sample:

ctypes._endian                 34     12    35%   15-20, 24-32, 50-60
ctypes.macholib                 1      1   100%   
email                          29     25    86%   56-57, 65-66
email.errors                   15     14    93%   39

How do I exclude these packages?

oz123
  • 27,559
  • 27
  • 125
  • 187
Chris Williams
  • 11,647
  • 15
  • 60
  • 97

1 Answers1

10

Try the nosetests --cover-package=<name> option. It will restrict coverage output to the listed packages/modules. You can use it more than once if your tests cover multiple packages.

samplebias
  • 37,113
  • 6
  • 107
  • 103
  • 4
    Note, you can use the `--cover-package=` switch multiple times if you want more than one package. – mc_electron Apr 07 '14 at 14:13
  • 1
    I've spent 15 minutes wondering why I only got one (the last) listed cover-package using a config file, but stupidly I had multiple invocations of `cover-package=foo \n cover-package=bar`. I'm a dumbass but hopefully someone else sees this! – Bolster Dec 17 '14 at 18:25
  • In order to specify multiple packages, one needs to separate them with commas like `--cover-package=first.package,another.package`. This is somehow not explicitly described even in [the nosetests docs](https://nose.readthedocs.io/en/latest/usage.html?highlight=nose_cover_package), but I leared it from the *example* here: https://nose.readthedocs.io/en/latest/usage.html?highlight=nose_cover_package . Using the parameter multiple times apparently leads to only the last one considered. – Yushin Washio Jul 08 '21 at 13:05