Open jieru-hu opened 3 years ago
Why do you need -Werror
at all though, if you have filterwarnings = error
in your config?
Thanks for taking a look.
Having -Werror
for all pytest
is how the CI is setup for my project - I also tried removing error
from pytest.ini, didn't help either.
Same problem here, I can reproduce it very easily.
# pytest.ini
[pytest]
filterwarnings =
ignore::FutureWarning
# test_with_warning.py
import warnings
from datetime import datetime
def foo():
warnings.warn(message="this won't work after 2030", category=FutureWarning)
if datetime.now() > datetime(year=2030, month=1, day=1):
raise RuntimeError
import pytest
def test_foo_rely_on_pytest_ini():
foo()
@pytest.mark.filterwarnings("ignore::FutureWarning")
def test_foo_marked():
foo()
/tmp/tmp.oi4oeAN6If$ pytest -W error .
======================================== test session starts ========================================
platform linux -- Python 3.8.10, pytest-7.4.0, pluggy-1.3.0
rootdir: /tmp/tmp.oi4oeAN6If
configfile: pytest.ini
collected 2 items
test_with_warning.py F. [100%]
============================================= FAILURES ==============================================
____________________________________ test_foo_rely_on_pytest_ini ____________________________________
def test_foo_rely_on_pytest_ini():
> foo()
test_with_warning.py:9:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
def foo():
> warnings.warn(message="this won't work after 2030", category=FutureWarning)
E FutureWarning: this won't work after 2030
test_with_warning.py:5: FutureWarning
====================================== short test summary info ======================================
FAILED test_with_warning.py::test_foo_rely_on_pytest_ini - FutureWarning: this won't work after 2030
==================================== 1 failed, 1 passed in 0.02s ====================================
$ pip freeze
exceptiongroup==1.1.3
iniconfig==2.0.0
packaging==23.1
pluggy==1.3.0
pytest==7.4.0
tomli==2.0.1
-W error
is great to find unexpected issues (e.g. the np.bool
deprecation warning), so this is an important feature.
Hi, first of all, thanks for the wonderful library!!
My code raises UserWarnings and I want to ignore them when running
python -Werror .
. I've been following this doc.Minimal repro:
Run:
If instead I decorate the test with
@mark.filterwarnings("ignore::UserWarning")
,pytest -Werror
runs with no issue. I have many tests that need the warning filter, so adding decorate to each of them is really not ideal. Is it possible to control the filtering withpytest.ini
?pip list
pytest and operating system versions
versions are in the example output, I'm on MAC OS catalina 10.15
pip list
from the virtual environment you are using