使用nosetests --pdb 选项设置断点 [英] setting breakpoints with nosetests --pdb option

查看:52
本文介绍了使用nosetests --pdb 选项设置断点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

nosetests --pdb 让我在错误或失败时停下来,但这对于我的需要来说太晚了.在执行期间单步执行代码有助于我调试问题所在.

nosetests --pdb let's me halt upon error or failure, but this is too late for my needs. Stepping through code during execution helps me debug where the problem is.

然而,nosetests 很有用,因为它们允许依赖于相对导入的测试(即包中的测试).

However, nosetests are helpful as they allow tests that rely on relative imports (i.e. tests in a package).

如何在执行测试之前设置断点?目前我正在使用:

How can I set breakpoints before the tests are executed? Currently I'm using:

python -m pdb /path/to/my/nosetests testfile.py

这个解决方案是不够的.Nosetests 干扰 pdb 输出,我的键盘控制(例如箭头键)坏了.

This solution isn't adequate. Nosetests interfere with pdb output, and my keyboard controls (e.g. arrow keys) are broken.

使用导入pdb;pdb.set_trace() 看起来是个好主意,但是鼻子测试阻止了我对 pdb 控制台的访问.

Using import pdb; pdb.set_trace() would seem like a good idea, however nosetests is blocking my access to the pdb console.

推荐答案

可以添加

import pdb; pdb.set_trace() 

您希望在调试器中停止的源代码中的任何位置.

anywhere in your source that you want to stop in the debugger.

确保将 -s 传递给鼻子,以便它不会捕获 stdout.

Make sure you pass -s to nose so that it does not capture stdout.

这篇关于使用nosetests --pdb 选项设置断点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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