如何在 py.test 上选择多个测试?

Alm*_*lho 6 pytest

我熟悉py.test -k string用于选择string名称中包含 的所有测试并运行它的命令。

我想要的是选择具有多个string参数的测试,例如OR逻辑选择。例如,假设我有 3 个测试:

  • test_should_connect
  • test_should_execute
  • test_should_return

假设我只想跑步,test_should_connect而且test_should_return只是。我在py.test 文档中寻找答案,为此我应该使用以下命令:

py.test -k "connect or return"
Run Code Online (Sandbox Code Playgroud)

但是,这不起作用=/

hpk*_*k42 8

py.test -k "connect or return"应该管用。你在使用 pytest==2.3.4 吗?您能否将“py.test”的输出与测试一起粘贴?

  • 从 pytest-2.5.1 ``py.test -k "connect or return"`` 不幸的是不起作用,因为你不能在这样的表达式中使用 python 关键字。``-k "connect or retur"`` 会起作用。pytest 目前遵循 python 来评估匹配表达式,这是“不使用关键字”的限制的来源。 (3认同)