我想抑制回溯输出,以简单地将状态显示为正常或失败、错误 有时用单行来解释失败。
我们该怎么做?看起来tracebacklimit=0 不起作用。
import sys
sys.tracebacklimit = 0
def test_something():
assert 1 == 2
执行显示回溯
# nosetests a.py -v
a.test_something ... FAIL
======================================================================
FAIL: a.test_something
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/lib/python2.6/site-packages/nose/case.py", line 197, in runTest
self.test(*self.arg)
File "/root/a.py", line 6, in test_something
assert 1 == 2
AssertionError
----------------------------------------------------------------------
Ran 1 test in 0.001s
FAILED (failures=1)
最佳答案
如果没有writing,很难做到这一点你自己的插件,可能与 Failure Detail 非常相似。如果您最终要实现一个插件,您可以将结果输出到 stdout,并通过将 Nose 重定向到 null 来抑制 stderr 输出。或者,使用现有的 xunit用于测试摘要并忽略 Nose 输出的插件。
关于python - notest - 使用 sys.tracebacklimit = 0 抑制回溯不会生效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30453257/