Pytest-django: Catching Django-specific warnings in pytest

Created on 21 Nov 2017  ·  3Comments  ·  Source: pytest-dev/pytest-django

I would like to turn the RemovedInNextVersionWarning warnings to errors, as described in https://docs.pytest.org/en/latest/warnings.html

Unfortunately, when I add to pytest.ini the following lines:

filterwarnings =
    error::RemovedInDjango20Warning

I end up with (it is looking strictly for Python internal warnings):

INTERNALERROR>   File "/myfolder/python3.6/warnings.py", line 236, in _getcategory
INTERNALERROR>     raise _OptionError("unknown warning category: %r" % (category,))
INTERNALERROR> warnings._OptionError: unknown warning category: 'RemovedInDjango20Warning'

Should/could pytest-django as a plugin make pytest aware of more possible warnings to handle?

Bonus question (slightly out of the scope): Even better would be a possibility to filter out the DjangoWarnings coming from the written code to the warnings coming from other libraries :-)

bitesize documentation question

Most helpful comment

Use the full name:

filterwarnings =
    error::django.utils.deprecation.RemovedInDjango20Warning

Even better would be a possibility to filter out the DjangoWarnings coming from the written code to the warnings coming from other libraries

More a feature for pytest I guess?!
It can be achieved using a logging filter, where you look for it record.getMessage() starts with your path.

All 3 comments

Use the full name:

filterwarnings =
    error::django.utils.deprecation.RemovedInDjango20Warning

Even better would be a possibility to filter out the DjangoWarnings coming from the written code to the warnings coming from other libraries

More a feature for pytest I guess?!
It can be achieved using a logging filter, where you look for it record.getMessage() starts with your path.

Sweet @blueyed !!!
Thanks for the hint!

I ended up discarding the few problems specifically, using this:

filterwarnings =
    error::django.utils.deprecation.RemovedInNextVersionWarning
    ignore::django.utils.deprecation.RemovedInNextVersionWarning:ajax_select.*

A pity that there are no mention of it in the docs. I am willing to submit a small PR regarding this. Where should it be? In configuring_django maybe?

A PR for the docs would be nice indeed.
I don't know them really though, so put it where you would have expected it.. ;)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

koxu1996 picture koxu1996  ·  3Comments

rodrigorodriguescosta picture rodrigorodriguescosta  ·  4Comments

tolomea picture tolomea  ·  4Comments

ojake picture ojake  ·  6Comments

AndreaCrotti picture AndreaCrotti  ·  5Comments