[英]Detecting failures in nosetests
I have something like this as a sampler: 我有这样的采样器:
class TestMe(object):
def test_a(self):
assert 'c' == '1'
print "I am here"
and nosetests gives me the following error correctly 和鼻子测试正确地给我以下错误
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
On the other hand, if I have a script like this which is also run by 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
When I run the above with nose tests, the it says: 当我通过鼻子测试运行以上命令时,它说:
nosetests test_110.py --tc-file ../configs/test_config.cfg -v
test_110.TestMe.test_b ... ok
----------------------------------------------------------------------
Ran 1 test in 0.026s
OK
Whereas only when I look at the log file I know that it has failed. 而只有当我查看日志文件时,我才知道它已失败。 How can I make the failure show up on the CLI?
如何使故障显示在CLI上?
您可以断言status ['status'] =='passed',也可以在if语句失败的情况下raise AssertionError('connection failed')
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.