2014-10-31 112 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')