为什么我无法使用 pdb 交互式调试器中断正在运行的测试?

发布于 2024-08-22 08:41:08 字数 741 浏览 4 评论 0原文

如何使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清欢 2024-08-29 08:41:08

您是否尝试过 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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文