pythonpython-3.xtestingpytestpytest-markers

Get a list of all custom markers in Pytest


If I have a simple test case with my own custom markers like:

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

How can I get the list of whole custom markers, because pytest -v --markers returns a list of predefined 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

without

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

Solution

  • You need to add the marker names to your pytest.ini to register them. See https://docs.pytest.org/en/latest/example/markers.html#registering-markers