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.
pip install pytest-taggingVerified import paths — ran on the pinned version, not inferred.
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"`.
Carefully design your tag selection and exclusion logic. If a test is unexpectedly skipped, check if it has any tags listed in `--exclude-tags`.
Always use `@pytest.mark.tags("your_tag")` provided by `pytest-tagging` for arbitrary tags instead of `pytest.mark.<your_custom_tag>` if you want to avoid explicit marker registration. If you want to use standard `pytest.mark` markers, ensure they are registered or you are not using `strict_markers=True`.Always check the `pytest-tagging` release notes and PyPI metadata for the `requires_python` and `install_requires` to ensure compatibility with your `pytest` version. Upgrade `pytest-tagging` to the latest version (1.6.0+) for broader `pytest` compatibility.
Instead of `@pytest.mark.your_custom_tag`, use `@pytest.mark.tags("your_custom_tag")`. `pytest-tagging` will handle the dynamic tagging without requiring explicit registration for each tag.Double-check the tags on your test functions and classes for accuracy. Verify the `--tags` command-line argument for typos or logical errors (e.g., `pytest --tags "tag1 and tag2"` will only run tests with *both* tags). Use `pytest --collect-only` to see collected tests and their marks/tags without running them.
Ensure you are importing `pytest` and using `@pytest.mark.tags("your_tag")`. Do not try to import `tag` or `mark_tags` from `pytest_tagging`.