2013-03-07 78 views
1

nose發現以test_開頭的測試以及unittest.TestCase的子類。在單元測試子類NOT中運行單一測試功能

如果希望運行單個TestCase測試,如:

# file tests.py 
class T(unittest.TestCase): 
    def test_something(): 
     1/0 

這可以在命令行上進行有:

nosetests tests:T.test_something 

我有時喜歡寫一個簡單的函數,並跳過所有unittest樣板:

def test_something_else(): 
    assert False 

在這種情況下,測試當它運行我所有的測試時仍然會由nose運行。但是,如何使用(Unix)命令行告訴nose僅運行該測試?

回答

3

這將是:

nosetests tests:test_something_else 

另外一個端頭是用屬性

from nose.plugins.attrib import attr 

@attr('now') 
def test_something_else(): 
    pass 

要運行具有標記的屬性的所有的測試中,執行:

nosetests -a now 

反之,避免運行那些測試:

nosetests -a !now 
+0

完美!不知道爲什麼我沒有在我周圍徘徊時偶然發現。謝謝! – JohnJ 2013-03-07 23:41:48