Skip to main content
PyPI version Python versions See Build Status on GitHub Actions

A pytest plugin that adds the xfail_err marker to xfail a test that failed with the specified error message in the captured stdout, stderr or log output.

This plugin can be useful in the following cases:

  • there are many tests failing due to sporadic problems (e.g., caused by an unstable network or sporadic crashes of a running third-party subprocess) and you want to save time analyzing test reports by splitting known flaky tests failures from meaningful software defects

  • it is necessary to ensure that the original error in the test marked as xfail does not change in future revisions

Requirements

  • Python >= 3.8

  • pytest >= 6.2.0

Installation

pip install pytest-errxfail

Usage

Just add the xfail_err marker to the tests you need with the following arguments:

  • positional argument with the error message pattern (can be also specified as the pattern kwarg)

  • reason keyword argument - xfail reason (optional)

  • matcher keyword argument - the type of message pattern matching (optional):

    • plain - simple substring search (default)

    • re - regular expression (with re.MULTILINE flag)

    • glob - Unix shell-style wildcard (via fnmatch)

Example:

@pytest.mark.xfail_err('Error when downloading https://example.com/data* - connection refused',
                       matcher='glob', reason='unstable network')
def test_download_file():
    run("echo 'Error when downloading https://example.com/data12 - connection refused' && exit 1",
        shell=True, check=True)

Output:

$ pytest -v
=============================== test session starts ================================
platform linux -- Python 3.12.3, pytest-8.3.4, pluggy-1.5.0 -- /tmp/venv/bin/python3
cachedir: .pytest_cache
rootdir: /media/eltio/d893d5b1-92cd-4a48-a51e-7e94a871dbf1/repo/current/test_py
plugins: errxfail-0.1.0
collected 1 item

test_demo.py::test_download_file XFAIL (unstable network)                    [100%]

================================ 1 xfailed in 0.03s ================================

Issues

If you encounter any problems, feel free to file an issue along with a detailed description and a minimal reproducible example.

License

Distributed under the terms of the MIT license, “pytest-errxfail” is free and open source software

Metadata

Release files for pytest-errxfail 0.1.0

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-errxfail 0.1.0
File Size Uploaded
pytest_errxfail-0.1.0.tar.gz 6.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-errxfail 0.1.0
File Interpreter ABI Platform
pytest_errxfail-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 12.5 kB

Release files / pytest_errxfail-0.1.0.tar.gz

Download URL pytest_errxfail-0.1.0.tar.gz
Size 6.1 kB
Tags Source
SHA-256 checksum
How to use checksums
29e80c7ace1f005c2c5235b57b282dac6bd36352f2fb10c8a9e0170214723779
BLAKE2b-256 checksum
How to use checksums
49819a8c8a3b4c8f02bf2ca11b4b8690db21002ee0f6767f3b661d71782e94a3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.3

Release files / pytest_errxfail-0.1.0-py3-none-any.whl

Download URL pytest_errxfail-0.1.0-py3-none-any.whl
Size 6.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
74882e5ec99b7161ac20f937e95efc72ecd500326f2e51e1ef321538bff3b806
BLAKE2b-256 checksum
How to use checksums
41b741b4dd23375f6c155635e6145ae304122e70eca309075d134e6333347474
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.3

Release history Release notifications | RSS feed

This release

0.1.0 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