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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest_tags-0.8.2.tar.gz (66.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_tags-0.8.2-py3-none-any.whl (32.7 kB view details)

Uploaded Python 3

File details

Details for the file pytest_tags-0.8.2.tar.gz.

File metadata

  • Download URL: pytest_tags-0.8.2.tar.gz
  • Upload date:
  • Size: 66.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.14.4

File hashes

Hashes for pytest_tags-0.8.2.tar.gz
Algorithm Hash digest
SHA256 933ebe5fae2d353a7c7b42570ef5d34c17a04ff543ecf3edc6e62d9543fd4deb
MD5 89ed28e26a7ec3290bda1acf7d30f581
BLAKE2b-256 337c830bc2127a87ce17fca10ff82f64e83f6474cb1502419dcb40a7d6422f34

See more details on using hashes here.

File details

Details for the file pytest_tags-0.8.2-py3-none-any.whl.

File metadata

  • Download URL: pytest_tags-0.8.2-py3-none-any.whl
  • Upload date:
  • Size: 32.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.14.4

File hashes

Hashes for pytest_tags-0.8.2-py3-none-any.whl
Algorithm Hash digest
SHA256 cabf90bfa21b943b5b44eba55809274b4481474968f80e57c859cd67962b62f9
MD5 f34f6d52c5f42851164e40ce30930e2e
BLAKE2b-256 39946cae5215f10738472af2352426f374aa2cfd474ea2a175213df17b1a08fb

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.8.2 This release

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page