I am about to upgrade from Django 1.9 to 1.10 and would like to test if I have some deprecated functionality.
However using
python -Wall manage.py test
will show tons and tons of warnings for Django 2.0. Is there a way to suppress warnings only for 2.0 or show only warnings for 1.10?
Use warnings. filterwarnings() to ignore deprecation warnings filterwarnings(action, category=DeprecationWarning) with action as "ignore" and category set to DeprecationWarning to ignore any deprecation warnings that may rise. Leave category unset to ignore all warnings.
To warn about deprecation, you need to set Python's builtin DeprecationWarning as category. To let the warning refer to the caller, so you know exactly where you use deprecated code, you have to set stacklevel=2 .
Deprecation warnings are a common thing in our industry. They are warnings that notify us that a specific feature (e.g. a method) will be removed soon (usually in the next minor or major version) and should be replaced with something else.
Add this to your manage.py
:
import warnings
from django.utils.deprecation import RemovedInDjango110Warning
warnings.filterwarnings('always', category=RemovedInDjango110Warning)
Change 'always'
to 'default'
to ignore redundant messages or to 'error'
to cause the program to fail on warnings.
A good way to limit the output to only show deprecation warnings is running:
python -Wd manage.py check
or
python -Wd manage.py test
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With