pdb.set_trace() 导致鼻子测试冻结,不会进入调试器
我正在使用鼻子测试运行一套测试(.py 文件)。使用经典的
import pdb; pdb.set_trace()
鼻子测试运行永远不会完成。它只是挂在断点设置的位置,但永远不会落入 pdb 调试器中。
有什么想法为什么会这样吗?我尝试将断点移动到多个不同的位置(其他测试函数、其他文件),但无济于事。
I'm running a suite of tests (.py files) using nosetests. Using a classic
import pdb; pdb.set_trace()
the nosetests run just never completes. It just hangs right where the breakpoint has been set, but never drops into the pdb debugger.
Any ideas why this would be? I've tried moving the breakpoint to a number of different positions (other test functions, other files) to no avail.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用
-s
/--nocapture
选项运行nose,您将能够看到pdb提示符并正常与调试器交互。如果使用命令行,这意味着:-
Run nose with the
-s
/--nocapture
option and you'll be able to see the pdb prompt and interact with the debugger normally.If using the commandline that means:-
Nose 正在捕获输出并重定向它。因此,断点已命中,但您只是看不到它。您需要关闭输出重定向,以便调试输出显示在屏幕上。
鼻子可以为您做到这一点
如果您使用:而不是:,
Nose is capturing the output and redirecting it. So, the breakpoint is hit, but you just don't see it. You need to turn off the output redirection so that the debug output shows up on the screen.
Nose can do this for you, if you use:
instead of:
就我而言,标志 -s/--nocapture 仍然没有解决它并将编译器放入 pdb 中。
您可以考虑的另一个原因是,如果您使用 MySQL 等数据库作为测试的一部分,则它不会被另一个同时进程锁定。就我而言,我启动了一个 python shell 通过 SQL Alchemy 查询 MySQL 数据库,并且锁定了表。结果,我的鼻子测试挂起 - 没有运行/退出。
我杀死了锁定表的 python 进程,Nose 又回来嗅探
> $ ps auxww | grep 蟒蛇 | awk '{print $2}' | sudo xargs Kill -9
In my case the flag the flag -s/--nocapture, still didn't resolve it and drop the compiler into pdb.
One other reason that you could look into is if you're using a database such as MySQL as part of your tests, that it's not locked by another simultaneous process. In my case, i had started a python shell to query the MySQL database through SQL Alchemy and that had locked up the tables. As a result, my nose tests were hanging - not running/exiting.
I killed the python processes which were locking up the tables and Nose was back up sniffing
> $ ps auxww | grep python | awk '{print $2}' | sudo xargs kill -9