Pytest warnings and how to turn them off

cagil
May 25, 2021

--

If you are finding yourself lost in warnings when running pytest, there are two paths you can follow. Fix the cause of the warning so that you can view your test results or find a way to surpass all or partially.

Lately I am seeing a lot of RemovedInDjango40Warning when running pytest locally and none of them are from my own codebase but from dependencies.

Today I learned how to ignore specific warnings. In your pytest.ini or pyproject.toml or setup.cfg you can define:

# setup.cfg
[tool:pytest]
filterwarnings =
ignore::django.utils.deprecation.RemovedInDjango40Warning
# pytest.ini
[pytest]
filterwarnings =
ignore::django.utils.deprecation.RemovedInDjango40Warning

This setting didn’t hide all warnings, but one specific warning and I am still being reminded for the rest each time I run tests.

You can read all about pytest warnings from pytest docs: https://docs.pytest.org/en/6.2.x/warnings.html

--

--

cagil
cagil

Written by cagil

Python developer, she/her

No responses yet