Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does nosetests say --with-coverage is not an option?

I am using nosetests to automatically discover and run my unittests. I would also like to have it generate coverage reports.

When I run nosetests with the following command everything works just fine

nosetests .

I looked up online that to generate the coverage, nosetests has a command line argument --with-coverage. I also double checked that this command exists using nosetests --help. However, whenever I run the following command I get the following output

nosetests --with-coverage .
Usage: nosetests [options]

nosetests: error: no such option: --with-coverage

I double checked that the coverage plugin is installed by running

nosetests --plugins

coverage shows up in the list along with a bunch of other plugins.

I also know I have coverage installed because I can manually run the coverage data collection using something along the lines of:

coverage run test.py

Am I misusing the --with-coverage option? Or is there something else I am missing?

Thanks in advance.

like image 499
rhololkeolke Avatar asked Nov 09 '12 07:11

rhololkeolke


3 Answers

I never got the command line options working. I did what Janne Karila suggested and created a setup.cfg file in my projects main directory. Once I had that file I could just run nosetests with no arguments and everything would run.

One problem I had when trying to create my document was that I couldn't figure out what parameters were allowed in the config. But it turns out that any of the commands listed here https://nose.readthedocs.org/en/latest/usage.html#options can be used. Just leave off the double dashes before the command.

For reference my current config file is

[nosetests]
verbosity=1
detailed-errors=1
with-coverage=1
cover-erase=1
cover-package=application
cover-html=1
cover-html-dir=htmlcov
where=tests

This config file says to use coverage, to erase the previous run's coverage, to only report on the files in the application package, and to output an html report to the htmlcov directory.

Hopefully this will help someone else in the future.

like image 186
rhololkeolke Avatar answered Oct 17 '22 01:10

rhololkeolke


Your syntax is correct. It maybe an issue with your environment, double check your python environment and where your have nose and coverage installed. As a sanity check, you can quickly setup a new virtualenv, install nose, and run the command with the coverage option.

like image 32
Brian Cajes Avatar answered Oct 17 '22 02:10

Brian Cajes


As of nose 1.3.7 - the most recent version available on Pypy - that command doesn't exist:

https://github.com/nose-devs/nose/blob/release_1.3.7/nose/plugins/cover.py

It looks like the documentation is being generated from the master branch of the project that does have those options available:

https://github.com/nose-devs/nose/blob/master/nose/plugins/cover.py

What you can do is install nose from the master branch like this:

pip install git+https://github.com/nose-devs/nose@master --upgrade

It will say it just installed 1.3.7 but that's only because the version hasn't been bumped in the project setup.py file yet: https://github.com/nose-devs/nose/blob/master/setup.py#L4

Remember you have just installed an unreleased version of nose, there may be other bugs.

like image 3
lsh Avatar answered Oct 17 '22 02:10

lsh