2016-11-10 92 views
0

我想运行unittest.TestCase的子类中包含的单个测试,使用nose2后跟How to run specific test in Nose2,但它似乎不适用于我。我使用下面的示例脚本,我将其命名mickey_mouse_test.py如何在nose2中运行单个测试用例

import unittest 

class TestMickeyMouse(unittest.TestCase): 
    def test_1plus1is2(self): 
     self.assertTrue(1+1 == 2) 

    def test_to_uppercase(self): 
     self.assertEqual("hello".upper(), "HELLO") 

if __name__ == "__main__": 
    unittest.main() 

如果我在同一个目录下运行nose2 mickey_mouse_test,它运行的模块中的所有测试:

[email protected]:~/Documents/Scratch$ nose2 mickey_mouse_test 
.. 
---------------------------------------------------------------------- 
Ran 2 tests in 0.001s 

OK 

然而,如果我尝试只是test_to_uppercase像这样跑,我得到一个错误:

[email protected]:~/Documents/Scratch$ nose2 mickey_mouse_test.test_to_uppercase 
E 
====================================================================== 
ERROR: mickey_mouse_test.test_to_uppercase (nose2.loader.LoadTestsFailure) 
---------------------------------------------------------------------- 
AttributeError: module 'mickey_mouse_test' has no attribute 'test_to_uppercase' 

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

FAILED (errors=1) 

如果我使用-s选项我仍然得到一个错误,ALBE它不同的一个:

[email protected]:~/Documents/Scratch$ nose2 -s mickey_mouse_test.test_to_uppercase 
E 
====================================================================== 
ERROR: mickey_mouse_test.test_to_uppercase (nose2.loader.LoadTestsFailure) 
---------------------------------------------------------------------- 
OSError: /home/kurt/Documents/Scratch/mickey_mouse_test.test_to_uppercase is not a directory 

---------------------------------------------------------------------- 
Ran 1 test in 0.000s 

FAILED (errors=1) 

我也试着阅读“指定测试运行”,在http://nose2.readthedocs.io/en/latest/usage.html,在其中指出的是,“Python对象部分”应该是“带点名称”部分。我不明白为什么在这种情况下,mickey_mouse_test.test_to_uppercase不是'虚线名称'。任何想法为什么这不起作用?

回答

相关问题