2014-10-31 159 views
0

我有這樣的事情作爲一個採樣:,檢測故障

class TestMe(object): 
    def test_a(self): 
     assert 'c' == '1' 
     print "I am here" 

和nosetests給了我下面的錯誤正確

nosetests test_me.py --tc-file ../configs/test_config.yaml -v 

test_me.TestMe.test_a ... FAIL 

============ ================================================== ========

FAIL: test_me.TestMe.test_a 
---------------------------------------------------------------------- 
Traceback (most recent call last): 
    File "/usr/local/lib/python2.7/site-packages/nose/case.py", line 197, in runTest 
    self.test(*self.arg) 
    File "/tests/test_me.py", line 7, in test_a 
    assert 'c' == '1' 
AssertionError 

在另一方面,如果我有這樣的劇本也是由nosetests運行:

class TestMe(object): 
    def __init__(self): 
     ............... 
    def test_b(self): 
     status = {'status': 'pass'} #by default 
     if status: 
      print("PASS: Connection was successful") 
     else: 
      print("FAIL: Connection was NOT successful") 
      status['status'] = "fail" #updating status in dictionary 
     return status 

當我運行上面鼻子的測試中,它說:

nosetests test_110.py --tc-file ../configs/test_config.cfg -v 
test_110.TestMe.test_b ... ok 

---------------------------------------------------------------------- 
Ran 1 test in 0.026s 

OK 

,而只有當我看看我知道它失敗的日誌文件。我如何使CLI顯示失敗?

回答

1

您可以在status ['status'] =='已通過'上聲明,或者您可以在失敗if case語句中使用raise AssertionError('connection failed')