È menzionato nella documentazione (http://nose.readthedocs.org/en/latest/api/core.html) ma non sembrano esserci esempi e provare sembra eseguire tutti i test in il cwd.Usa nose.run() o nose.main() per eseguire i test in un modulo specifico
8
A
risposta
8
Prova questo:
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
ti porterà:
test_module.test_me ... ok
----------------------------------------------------------------------
Ran 1 test in 0.001s
OK
INFO:root:all tests ok: True
6
Ecco una versione minimale di una conduttura per il naso:
if __name__ == '__main__':
import nose
nose.run(defaultTest=__name__)
E una versione per nose2:
if __name__ == '__main__':
import nose2
nose2.main()