2016-11-10 91 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不是'虛線名稱'。任何想法爲什麼這不起作用?

回答

相關問題