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.
In IPython, use %pdb before running the test
In [9]: %pdb
Automatic pdb calling has been turned ON
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
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.
精彩评论