【问题标题】:Pytest on Python Tools for visual studio用于 Visual Studio 的 Python 工具上的 Pytest
【发布时间】:2013-12-02 10:38:55
【问题描述】:

可以调试在 Visual Studio 2010 上使用 pytest 库的 python 测试吗?我在解释器参数上添加了-m pytest,但没有命中断点,我只能运行测试脚本而不调试它。

【问题讨论】:

    标签: python visual-studio unit-testing pytest ptvs


    【解决方案1】:

    如果您能更具体一些,那就太好了。当我使用 pytools 时,我发现它非常有用,并在 http://pytools.codeplex.com 找到了很大的帮助。您可以查看http://pytools.codeplex.com/discussions

    也请查看Can I debug with python debugger when using py.test somehow?Python Unit Testing: Automatically Running the Debugger when a test fails 寻求帮助,因为他们提出了类似的问题。

    【讨论】:

    • 感谢 fscore 的回答。我需要使用 Visual Studio 的 Python 工具而不是 Python 调试器(pdb)来调试 pytest 测试。在 Visual Studio 上,在项目属性->调试->解释器参数上,我添加了“-m pytest”,因此测试脚本将作为“python.exe -m pytest test_scripts.py”运行。我在测试脚本上添加了断点,我使用“从调试开始”运行它,但没有命中断点,测试只是在没有调试的情况下运行。
    • 回复:codeplex 链接。 “这个网站,包括讨论和问题,不再受到积极监控。”。遗憾的是,他们去了 Github。
    【解决方案2】:

    Pytest 建议创建一个独立的启动脚本。

    if __name__ == '__main__':
        import pytest
        pytest.main()
    

    这就是我所做的,PTVS 调试对我有用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多