Pytest Tagging

1.6.0 · active · verified Thu Apr 16

pytest-tagging is an active pytest plugin, currently at version 1.6.0, designed to simplify test categorization by allowing users to tag tests with arbitrary strings without the need for explicit marker registration. It enhances pytest's built-in capabilities, enabling granular selection and exclusion of tests based on these tags, and providing summary statistics like failed test counts per tag. The library typically sees several minor or patch releases per year, indicating active maintenance.

Common errors

Warnings

Install

Imports

Quickstart

Create a file named `test_example.py` with the content above. Then, run pytest from your terminal using the `--tags` option to select tests. You can combine tags with 'and', 'or', and 'not' logic. To run tests tagged 'smoke' or 'login', use `pytest --tags "smoke or login"`. To run tests tagged 'regression' but *not* 'critical', use `pytest --tags "regression not critical"`.

import pytest

# Tagging a test function
@pytest.mark.tags("smoke", "login")
def test_successful_login():
    assert 1 == 1

# Tagging a whole test class
@pytest.mark.tags("regression")
class TestUserProfile:
    def test_view_profile(self):
        assert True

    @pytest.mark.tags("critical")
    def test_update_profile(self):
        assert False # This test is expected to fail for demonstration

view raw JSON →