python - 想法运行/调试 py.test 单个测试而不是整个套件

标签 python intellij-idea pytest

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

enter image description here

这是我对调试器的设置。它运行整个测试套件。因此,我必须先运行所有测试,然后才能进入我要调试的测试。

最佳答案

在您的配置中,设置:

  • 定位到您的一个测试文件的相对路径,即 testsuite/psa/test_psa_integration.py
  • 关键字到一个关键字,用于标识您要专门运行的测试。如果测试是类的一部分,关键字应该是这样的:TestPsaIntegration and test_psa_integration_example

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

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

然后,回到您的文件(即 test_psa_integration.py),您只需右键单击测试代码的任意位置,然后选择 Run 'py.test in ...'Debug 'py.test in...' 这将自动创建一个新的运行/调试配置,如前所述。

关于python - 想法运行/调试 py.test 单个测试而不是整个套件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36718762/

相关文章:

python - 如何在一个 groupby 列上执行聚合选项,给出两列输出

python - 如何从Python列表中索引两个元素?

android - 在 Intellij IDEA 中子类化 Android 应用程序?

kotlin - 抑制 Intellij 中公共(public) API 函数的 "unused"警告(对于 Kotlin)

python - 为什么 pytest 中的列表与控制台的输出不同?

python - 键入 : incompatible type when declare typing. 类型 []

python - 设置数据类型为 Decimal 的 Pandas 数据框列的小数精度

intellij-idea - Lombok 插件与 2018.1 Intellij Idea 不兼容

python - 无法让 pytest 理解设置中的命令行参数

python - Pytest:根据假设生成总和为 1 的 float 列表