idea run/debug py.test 单个测试不是整个套件

Idea run/debug py.test single test not the whole suite

我正在创建一个 python 测试套件(使用 py.test)。我在 Idea 中编写测试代码,但我不知道如何调试单个测试。

这是我对调试器的设置。它 运行 是整个测试套件。所以我必须 运行 在到达我要调试的测试之前完成所有测试。

在您的配置中,设置:

  • 定位到您的一个测试文件的相对路径,即 testsuite/psa/test_psa_integration.py
  • 关键字到一个关键字,用于标识您正在尝试 运行 的具体测试。如果测试是 class 的一部分,关键字应类似于:TestPsaIntegration and test_psa_integration_example

我不使用 IntelliJ,但在 PyCharm 中,您可以轻松调试测试,而无需每次都添加 Run/Debug 配置这一繁琐的过程。

要使用 PyCharm 执行此操作,请转到: Preferences (or Settings) > Tools > Python Integrated Tools 并将 Default test runner 设置为 py.test

然后,返回您的文件(即 test_psa_integration.py),您可以在 测试代码中 的任意位置右击,然后 select Run 'py.test in ...'Debug 'py.test in...' 将自动创建新的 Run/Debug 配置,如前所述。

另一种方法是将 --no-cov --capture=no 添加到 附加参数 中。要使其他测试文件自动执行此操作,请将其添加到 Template 部分。