Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can pytest ignore a specific warning?

Tags:

python

pytest

I'd like pytest to ignore the RemovedInDjango20Warning.

I currently have this in pytest.ini

[pytest]
filterwarnings =
    ignore:RemovedInDjango20Warning

And that allows pytest to run, but does not suppress the warnings.

If I add a second colon, I get a lot of "INTERNAL ERROR" messages.

If I add a third colon, the tests run, but do not suppress the warnings.

I am afraid to add a fourth colon :)

~

I've also tried being more specific about the error:

ignore:django.RemovedInDjango20Warning

and

ignore:django.utils.deprecation.RemovedInDjango20Warning

and while those run, I'm still warned every time.

The INTERNALERRORs that I get are:

INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/home/chris/.pyenv/versions/3.6.10/lib/python3.6/warnings.py", line 246, in _getcategory
INTERNALERROR>     cat = getattr(m, klass)
INTERNALERROR> AttributeError: module 'django' has no attribute 'RemovedInDjango20Warning'
INTERNALERROR> 
INTERNALERROR> During handling of the above exception, another exception occurred:
INTERNALERROR> 
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/home/chris/.virtualenvs/website-36/lib/python3.6/site-packages/_pytest/main.py", line 196, in wrap_session
INTERNALERROR>     session.exitstatus = doit(config, session) or 0

[long traceback snipped]

INTERNALERROR>     raise _OptionError("unknown warning category: %r" % (category,))
INTERNALERROR> warnings._OptionError: unknown warning category: 'django.RemovedInDjango20Warning'

like image 938
Chris Curvey Avatar asked Jan 06 '20 18:01

Chris Curvey


1 Answers

While taking a second look based on @LaurentBristiel 's comments, I realized that I need two colons, PLUS the full path to the exception, so

[pytest]
filterwarnings =
    ignore::django.utils.deprecation.RemovedInDjango20Warning

Thanks to all!

like image 83
Chris Curvey Avatar answered Nov 15 '22 04:11

Chris Curvey