4

I want to run NoseTest from a Python script. But I want not only run it, but also measure test coverage.

Just now I have the following code:

import os
import sys
import nose

sys.path.append(os.path.dirname(os.path.abspath(os.path.dirname(__file__))))

import tests

if __name__ == "__main__":
    config = nose.config.Config(verbosity=3, stopOnError=False, argv=["--with-coverage"])
    result = nose.run(module=tests, config=config)

What should I add to get my coverage report?

2 Answers 2

2

Hell yeah! After some small debugging of Nose Test I've managed to do it!

if __name__ == "__main__":
    file_path = os.path.abspath(__file__)
    tests_path = os.path.join(os.path.abspath(os.path.dirname(file_path)), "tests")
    result = nose.run(argv=[os.path.abspath(__file__),
                            "--with-cov", "--verbosity=3", "--cover-package=phased", tests_path])
Sign up to request clarification or add additional context in comments.

Comments

0

EDIT: To run plugins with nose.run(), you need to use the 'plugins' keyword:

http://nose.readthedocs.org/en/latest/usage.html#using-plugins

Your code is all set -- you need to enable coverage via the runner. Simply run nose like this:

nosetests --with-coverage

There are more options here:

http://nose.readthedocs.org/en/latest/plugins/cover.html

FYI, you might need to run the following to get the coverage package:

pip install coverage 

7 Comments

I don't want to run nosetests as application: I have to run it on Windows machines that don't have it in path. So I should run it from Python. coverage package is already installed.
Whoops missed that. You should be able to add plugins via the plugins keyword: nose.readthedocs.org/en/latest/usage.html#using-plugins
It's for the commandline usage. I need their selection just in Python code.
"If you are running nose.main() or nose.run() from a script, you can specify a list of plugins to use by passing a list of plugins with the plugins keyword argument."
Oh, I've seen it too. But there was no one example how to pass them. I've tried plugins=["coverage"] and plugins=["nose-coverage"] but nothing changes. Maybe you can give me the right code snippet?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.