drop into an interactive session to examine a failed unit test

寵の児 提交于 2019-12-10 18:16:54

问题


I'd like to be able to enter an interactive session, preferably with IPython, if a unit test fails. Is there an easy way to do this?

edit: by "interactive session" I mean a full Python REPL rather than a pdb shell.

edit edit: As a further explanation: I'd like to be able to start an interactive session that has access to the context in which the test failure occurred. So for example, the test's self variable would be available.


回答1:


In IPython, use %pdb before running the test

In [9]: %pdb
Automatic pdb calling has been turned ON



回答2:


Nosetests runner provides --pdb option that will put you into the debugger session on errors or failures.

http://nose.readthedocs.org/en/latest/usage.html




回答3:


Are you really sure you want to do this? Your unit tests should do one thing, should be well-named, and should clearly print what failed. If you do all of that, the failure message will pinpoint what went wrong; no need to go look at it interactively. In fact, one of the big advantages of TDD is that it helps you avoid having to go into the debugger at all to diagnose problems.



来源:https://stackoverflow.com/questions/3517410/drop-into-an-interactive-session-to-examine-a-failed-unit-test

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!