nosetests coverage including Python packages
Asked Answered
F

1

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?

Firooc answered 30/3, 2011 at 20:25 Comment(0)
H
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.

Hexagonal answered 30/3, 2011 at 20:38 Comment(3)
Note, you can use the --cover-package=<name> switch multiple times if you want more than one package.Layman
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!Weekend
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, but I leared it from the example here: nose.readthedocs.io/en/latest/… . Using the parameter multiple times apparently leads to only the last one considered.Marinara

© 2022 - 2024 — McMap. All rights reserved.