获取所有自定义标记的列表

时间:2015-03-06 17:12:19

标签: python python-3.x pytest

如果我有一个简单的测试用例,我的自定义标记如下:

class TestClass:

    @pytest.mark.first
    def test_first(self):
        assert True

    @pytest.mark.second
    def test_second(self):
        assert True

    @pytest.mark.third
    def test_third(self):
        assert True

如何获取整个自定义标记的列表,因为$ py.test -v --markers会返回预定义标记的列表

@pytest.mark.skipif(condition)
@pytest.mark.xfail(condition, reason=None, run=True, raises=None)
@pytest.mark.parametrize(argnames, argvalues)
@pytest.mark.usefixtures(fixturename1, fixturename2, ...)
@pytest.mark.tryfirst
@pytest.mark.trylast

@pytest.mark.first
@pytest.mark.second
@pytest.mark.third

1 个答案:

答案 0 :(得分:5)

您需要将标记名称添加到pytest.ini以注册它们。见https://docs.pytest.org/en/latest/example/markers.html#registering-markers