进入交互式会话以检查失败的单元测试 [英] drop into an interactive session to examine a failed unit test

查看:172
本文介绍了进入交互式会话以检查失败的单元测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果单元测试失败,我希望能够进入交互式会话,最好是使用IPython。有没有一种简单的方法可以做到这一点?

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?

编辑:通过交互式会话我的意思是完整的Python REPL而不是pdb shell。

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

编辑修改:作为进一步的解释:我希望能够启动一个可以访问上下文的交互式会话测试失败发生了。例如,测试的 self 变量可用。

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.

推荐答案

在IPython中,在运行测试之前使用%pdb

In IPython, use %pdb before running the test

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

这篇关于进入交互式会话以检查失败的单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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