我有这样的东西作为采样器:
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上显示故障?
答案 0 :(得分:1)
您可以在状态['status'] =='通过'时断言,或者您可以在失败的if case语句中raise AssertionError('connection failed')
。