使用nosetests --pdb 选项设置断点
nosetests --pdb
让我在错误或失败时停止,但这对于我的需求来说已经太晚了。在执行过程中单步调试代码可以帮助我调试问题所在。
然而,nosetests 很有帮助,因为它们允许依赖相对导入的测试(即包中的测试)。
如何在执行测试之前设置断点? 目前我正在使用:
python -m pdb /path/to/my/nosetests testfile.py
此解决方案还不够。 Nosetests 会干扰 pdb 输出,并且我的键盘控件(例如箭头键)损坏。
使用导入pdb; pdb.set_trace() 似乎是一个好主意,但是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.
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
This solution isn't adequate. Nosetests interfere with pdb output, and my keyboard controls (e.g. arrow keys) are broken.
Using import pdb; pdb.set_trace() would seem like a good idea, however nosetests is blocking my access to the pdb console.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
比记住使用
-s
更好的是使用 Nose 附带的set_trace
变体。 添加将您想要中断的位置 到调试器中。将为您处理标准输入/输出重定向。我遇到的唯一奇怪的副作用是在鼻子运行期间调试时无法从 pdb 中重新启动代码(使用
run
)。Even better than remembering to use
-s
is to use theset_trace
variant that comes with Nose. Addwherever you'd like to break in to the debugger. The stdin/out redirection will be taken care of for you. The only strange side effect I've run into is the inability to restart your code from within pdb (using
run
) while debugging during a nose run.您可以
在源代码中添加要在调试器中停止的任何位置。
确保将
-s
传递给nose,这样它就不会捕获stdout
。You can add
anywhere in your source that you want to stop in the debugger.
Make sure you pass
-s
to nose so that it does not capturestdout
.如果你有ipython,为了无限的精彩使用:
*无限的精彩:就像 ipython - 自动完成,着色等。
If you have ipython, for unlimited awesomeness use:
*unlimited awesomeness: just like ipython - auto-completion, coloring etc.
如果您使用pytest,则可以使用
参见文档。
If you are using pytest, you can use
See documentation.