Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use nose.run() or nose.main() to run tests in a specific module

It's mentioned in the documentation (http://nose.readthedocs.org/en/latest/api/core.html) but there don't seem to be any examples, and trying it seems to run all tests in the cwd.

like image 400
neel Avatar asked Apr 11 '14 00:04

neel


1 Answers

Try this:

test_module.py:

import logging
import sys

import nose

logging.basicConfig(level=logging.INFO)

#here are some tests in this module
def test_me():
    pass

if __name__ == '__main__':
    #This code will run the test in this file.'

    module_name = sys.modules[__name__].__file__
    logging.debug("running nose for package: %s", module_name)

    result = nose.run(argv=[sys.argv[0],
                            module_name,
                            '-v'])
    logging.info("all tests ok: %s", result)

python test_module.py will get you:

test_module.test_me ... ok

----------------------------------------------------------------------
Ran 1 test in 0.001s

OK
INFO:root:all tests ok: True
like image 126
Oleksiy Avatar answered Sep 19 '22 15:09

Oleksiy