pytest plugin to mark a test as xfailed if it fails with the specified error message in the captured output
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pytest_errxfail-0.1.0.tar.gz.
File metadata
- Download URL: pytest_errxfail-0.1.0.tar.gz
- Upload date:
- Size: 6.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
29e80c7ace1f005c2c5235b57b282dac6bd36352f2fb10c8a9e0170214723779
|
|
| MD5 |
443774d12086b4a43db97c0ccdccc6c4
|
|
| BLAKE2b-256 |
49819a8c8a3b4c8f02bf2ca11b4b8690db21002ee0f6767f3b661d71782e94a3
|
File details
Details for the file pytest_errxfail-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pytest_errxfail-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
74882e5ec99b7161ac20f937e95efc72ecd500326f2e51e1ef321538bff3b806
|
|
| MD5 |
359d20b8859d03ec237f06746d50b371
|
|
| BLAKE2b-256 |
41b741b4dd23375f6c155635e6145ae304122e70eca309075d134e6333347474
|