2014-04-11 16 views

Trả lời

8

Hãy thử điều này:

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 sẽ giúp bạn:

test_module.test_me ... ok 

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

OK 
INFO:root:all tests ok: True 
6

Dưới đây là một phiên bản tối thiểu của một chính cho mũi:

if __name__ == '__main__': 
    import nose 
    nose.run(defaultTest=__name__) 

phiên bản dành cho mũi2:

if __name__ == '__main__': 
    import nose2 
    nose2.main() 
Các vấn đề liên quan