How to fix pytest ERROR while parsing the following warning configuration: ...
Problem:
You want to ignore a warning during a unit test using code such as
pytest_filterwarnings.py
@pytest.mark.filterwarnings("divide by zero encountered in log10")
def test_auto_suffix_1d(self):
# ...
but you see an error message such as
pytest_error.txt
ERROR: while parsing the following warning configuration:
divide by zero encountered in log10
This error occurred:
invalid action: 'divide by zero encountered in log10'
Solution
In the argument to @pytest.mark.filterwarnings(...)
you forgot the ignore:
prefix:
Instead of
pytest_filterwarnings_fixed.py
@pytest.mark.filterwarnings("divide by zero encountered in log10")
write
example.py
@pytest.mark.filterwarnings("ignore: divide by zero encountered in log10")
You may see an error like:
pytest_error_output.txt
INTERNALERROR> while parsing the following warning:
INTERNALERROR> configuration
Often the cause is an invalid pytest.ini
or pyproject.toml
configuration. Example pytest.ini
:
pytest.ini
[pytest]
addopts = -ra -q
python_files = tests.py test_*.py *_test.py
Validate your config and remove invalid options to fix the error.
Check out similar posts by category:
Python
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow