为什么我无法使用 pdb 交互式调试器中断正在运行的测试?
如何使用 pdb 交互式调试器中断正在运行的测试?
这是测试:
class UserTestCase(TestCase):
def test_register_should_create_UserProfile(self):
c = Client()
response = c.post('/account/register/', {u'username': [u'john'], u'email': [u'[email protected]'], u'bnewaccount': [u'Signup']})
self.assertEqual(response.status_code, 302)
import pdb; pdb.set_trace()
user = User.objects.get( username ='john')
self.assertTrue(user.get_profile())
当我尝试运行测试时:
$ python manage.py test
创建测试数据库。进度点“.”当测试通过时,开始在屏幕上进行。 然后进程停止。
我从来没有看到过 pdb>终端窗口中出现提示。
如何让pdb正常工作?
How can I break into a running test with the pdb interactive debugger?
This is the test:
class UserTestCase(TestCase):
def test_register_should_create_UserProfile(self):
c = Client()
response = c.post('/account/register/', {u'username': [u'john'], u'email': [u'[email protected]'], u'bnewaccount': [u'Signup']})
self.assertEqual(response.status_code, 302)
import pdb; pdb.set_trace()
user = User.objects.get( username ='john')
self.assertTrue(user.get_profile())
When I attempt to run the tests:
$ python manage.py test
The test database is created. The progress dots '.' begin to progress across the screen as the tests pass.
Then the progess stops.
I am never shown a pdb> prompt in the terminal window.
How can I get pdb to work properly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过 ipdb 而不是 vanilla pdb?我使用 ipdb 并且你想要做的工作正常。
或者,作为后备方案,为什么不在您正在测试的方法中、在返回响应之前尝试 pdb 调用?
Have you tried ipdb instead of vanilla pdb? I use ipdb and what you're trying to do works fine.
Alternatively, as a fallback, why not try the pdb call inside the method you're testing, just before the response is returned?