有没有办法只将一项测试标记为 运行?

Is there a way to mark only one test to run?

我正在调试一项失败的测试。有没有办法将一个测试标记为 运行?

类似于:

@pytest.only # it doesn't work
def test_some_test():
  ...

您可以用 pytest.mark 标记您的测试。标记是动态创建的,因此您几乎可以选择任何名称。 Here is a link to docs.

例如 tt.py:

import pytest

@pytest.mark.one_test
def test_foo():
    assert 1 == 1

def test_bar():
    assert 2 == 2

enter code here

然后 运行 和 pytest tt.py -m one_test :

pytest tt.py -m one_test

======================= test session starts =========================

platform darwin -- Python 3.6.3, pytest-3.6.1, py-1.5.3, pluggy-0.6.0

rootdir: /Users/foobarna/workspace/random, inifile:
collected 2 items / 1 deselected

tt.py .
[100%]

============= 1 passed, 1 deselected in 0.04 seconds ================