Skip to main content

Repo logo: grouped and tagged test results

Overview

Framework for building pytest plugins which works on tag- (i.e. marker-) based groupings of tests.

Features

  • Easy creation of plugin objects, each associated with a @pytest.mark.<...> marker used for tagging test functions, classes, and modules
  • Intuitive and automatic scoping of both explicitly-labeled and anonymous tags
  • Automatic grouping of tagged parametrized tests

Changelog

Refer to the Release notes.

Example

Consider the @pytest.mark.fail_fast_group marker provided by the package, which groups tests together and skips subsequent tests in a group if any earlier test in the same group failed:

from __future__ import annotations

from collections.abc import Generator
from typing import Literal

import pytest


@pytest.fixture
def good_fixture() -> int:
    return 1


@pytest.fixture
def bad_fixture() -> Generator[int, None, None]:
    raise RuntimeError('Bad fixture')
    yield 1


@pytest.mark.fail_fast_group(groupby='fixture')
@pytest.mark.parametrize('x, y', [(1, 2), (3, 4), (5, 6)])
@pytest.mark.parametrize('fixture', ['good_fixture', 'bad_fixture'])
def test_use_fixture(
    request: pytest.FixtureRequest,
    fixture: Literal['good_fixture', 'bad_fixture'],
    x: int,
    y: int,
) -> None:
    """
    This parametrized test uses a bad fixture in some subtests; with the
    `@pytest.mark.fail_fast_group` marker, all subtests using
    `good_fixture` are tagged and grouped together, while all subtests
    using `bad_fixture` end up in another group. As a result,
    only one failing test will be run in the latter group, while
    subsequent tests in the group will be skipped, citing the first
    failing test as the reason.
    """
    z = request.getfixturevalue(fixture)
    ...


@pytest.mark.fail_fast_group
def test_a_failing_test() -> None:
    """
    This test fails, causing later tests tagged with the anonymous
    `@pytest.mark.fail_fast_group` to be skipped.
    """
    raise RuntimeError('fail')


@pytest.mark.fail_fast_group
def test_skipped() -> None:
    """
    This test is skipped, because `test_a_failing_test()` is in
    the same anonymous group as it and has failed.
    """


@pytest.mark.fail_fast_group(scope='session')
def test_another_failing_test() -> None:
    """
    This test is not skipped, because while its tag is anonymous like
    `@pytest.mark.fail_fast_group` it is explicitly scoped to the entire
    session, while the implicit version is scoped to the module.
    """
    raise RuntimeError('failing again')


@pytest.mark.fail_fast_group(0)
def test_passing_test() -> None:
    """
    This test is not skipped, because its tag has an explicit label `1`;
    and is implicitly scoped to the module; thus, it does not fall in
    the same group as either `test_a_failing_test()` or
    `test_another_failing_test()`.
    """
 $ pytest -rs --tb=no -v test_module.py
============================= test sesstion starts =============================
...
test_module.py::test_use_fixture[good_fixture-1-2] PASSED                 [ 10%]
test_module.py::test_use_fixture[good_fixture-3-4] PASSED                 [ 20%]
test_module.py::test_use_fixture[good_fixture-5-6] PASSED                 [ 30%]
test_module.py::test_use_fixture[bad_fixture-1-2] FAILED                  [ 40%]
test_module.py::test_use_fixture[bad_fixture-3-4] SKIPPED (1 prior te...) [ 50%]
test_module.py::test_use_fixture[bad_fixture-5-6] SKIPPED (1 prior te...) [ 60%]
test_module.py::test_a_failing_test FAILED                                [ 70%]
test_module.py::test_skipped SKIPPED (1 prior test in the same group(...) [ 80%]
test_module.py::test_another_failing_test FAILED                          [ 90%]
test_module.py::test_passing_test PASSED                                  [100%]

=========================== short test summary info ============================
SKIPPED [2] test_module.py:20: 1 prior test in the same group(s) already failed 
({test: matched_tags}): {'test_module.py::test_use_fixture[bad_fixture-1-2]': [<
Tag "test_use_fixture(fixture='bad_fixture')">]}
SKIPPED [1] test_module.py:51: 1 prior test in the same group(s) already failed 
({test: matched_tags}): {'test_module.py::test_a_failing_test': [<Tag 'test_mod
ule.py'>]}
==================== 3 failed, 4 passed, 3 skipped in 0.08s ====================

The pytest plugin implementing @pytest.mark.fail_fast_group is built upon the rest of the package, which provides the facilities for doing such tag-/marker-based grouping.

Full documentation

Refer to the project repository: GitLab:TTsangSC/pytest-tags

Metadata

Release files for pytest-tags 0.8.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytest-tags 0.8.2
File Size Uploaded
pytest_tags-0.8.2.tar.gz 66.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-tags 0.8.2
File Interpreter ABI Platform
pytest_tags-0.8.2-py3-none-any.whl Python 3 none any Details

Total release size: 99.4 kB

Release files / pytest_tags-0.8.2.tar.gz

Download URL pytest_tags-0.8.2.tar.gz
Size 66.8 kB
Tags Source
SHA-256 checksum
How to use checksums
933ebe5fae2d353a7c7b42570ef5d34c17a04ff543ecf3edc6e62d9543fd4deb
BLAKE2b-256 checksum
How to use checksums
337c830bc2127a87ce17fca10ff82f64e83f6474cb1502419dcb40a7d6422f34
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.14.4

Release files / pytest_tags-0.8.2-py3-none-any.whl

Download URL pytest_tags-0.8.2-py3-none-any.whl
Size 32.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cabf90bfa21b943b5b44eba55809274b4481474968f80e57c859cd67962b62f9
BLAKE2b-256 checksum
How to use checksums
39946cae5215f10738472af2352426f374aa2cfd474ea2a175213df17b1a08fb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.14.4

Release history Release notifications | RSS feed

This release

0.8.2 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page