Search code examples
tagspytesttaggingmarkers

How to apply multiple tags to a test case in pytest?


In pytest you can mark a test case with a tag.

@pytest.mark.windows
def test_will_fail():
    assert False

Now above test case is marked with the tag 'windows'. Running pytest with pytest -m windows will execute only test cases which are marked with the tag 'windows'.

But what if I want to apply more than one tag? e.g. I would like to tag above test case with 'windows' and 'smoke'. How would I do that? (I haven't seen an example on that in pytest docs.)


Solution

  • Those are simply Python decorators which you can stack:

    @pytest.mark.smoke
    @pytest.mark.windows
    def test_will_fail():
        assert False