【问题标题】:Pytest - Breakpoints in tests are being skipped when debugging with VSCodePytest - 使用 VSCode 调试时跳过测试中的断点
【发布时间】:2021-11-10 11:54:55
【问题描述】:

在python模块integration_tests中,我有一个脚本可以通过文件run_tests.py中的pytest运行我的测试:

import pytest

if __name__ == "__main__":    
    pytest.main(['./integration_tests/']) # breakpoint here works, but no breakpoints in test methods

在我的docker-compose.yml 文件中,我附加了一个调试器并通过设置入口点来运行测试:

entrypoint: ["/usr/src/app/cvenv/bin/python3.8", "-m", "ptvsd", "--host", "0.0.0.0", "--port", "5678", "--wait", "./integration_tests/run_tests.py"]

run_tests.py 文件中的断点有效。但是之后没有断点被执行。

我如何才能真正调试测试,而不仅仅是在调用 pytest 之前?

【问题讨论】:

    标签: python docker-compose pytest vscode-debugger


    【解决方案1】:

    我不知道我可以使用两次-m 模块开关。所以现在我使用 ptvsd 调试选项将-m pytest 开关添加到入口点命令。 现在此命令运行 Visual Studio 调试器并调用测试。

    我无法使用 pytest.main 调用调试测试,因为它创建了一个单独的线程。

    【讨论】:

      猜你喜欢
      • 2020-01-27
      • 2011-09-28
      • 1970-01-01
      • 1970-01-01
      • 2020-04-23
      • 1970-01-01
      • 2010-12-13
      • 2013-04-21
      • 1970-01-01
      相关资源
      最近更新 更多