测试成功,仍然得到回溯 [英] Tests succeed, still get traceback

查看:19
本文介绍了测试成功,仍然得到回溯的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Python 的 unittest 库并且所有测试都成功了,但我仍然得到了一个回溯,我不明白如何解决这个问题.

I'm using Python's unittest library and all the tests succeed, but I still get a traceback and I can't understand how I can fix the problem.

........
----------------------------------------------------------------------
Ran 8 tests in 0.020s

OK

Traceback (most recent call last):
  File "C:\Users\Paul\Desktop\bloomfilter\test_bloomfilter.py", line 85, in <module>
    unittest.main()
  File "C:\Programming\PythonX86\Python27\lib\unittest\main.py", line 95, in __init__
    self.runTests()
  File "C:\Programming\PythonX86\Python27\lib\unittest\main.py", line 231, in runTests
    sys.exit(not self.result.wasSuccessful())
SystemExit: False
>>> 

推荐答案

您似乎在 Python shell 中运行,它会为您捕获异常以便您可以继续调试.如果您一直从命令行运行,则该行

It appears that you are running in the Python shell, which catches exceptions for you so you can continue debugging. If you had been running from the command line, the line

sys.exit(not self.result.wasSuccessful())

会以退出代码 0 退出您的程序,这表示成功(如果您不熟悉程序与 shell 的交互方式,这可能违反直觉).但是,由于您在解释器中运行,因此会捕获异常.

would have exited your program with an exit code of 0, which indicates success (this might be counterintuitive if you're unfamiliar with how programs interact with the shell). Since you're running in the interpreter, however, the exception is caught.

我建议您的程序或测试没有任何问题.unittests 框架可能只是没想到会以交互方式运行!

I would suggest that there is nothing wrong with your program or your tests. The unittests framework probably just didn't expect to be run interactively!

这篇关于测试成功,仍然得到回溯的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆