-
Notifications
You must be signed in to change notification settings - Fork 568
Closed
Labels
Description
Make all deprecation messages use the warnings.warn function.
Right now we use two different ways, some deprecation messages use logging.warning and some are using warnings.warn.
There was some discussion about using logging or warnings module for deprecation. In the Python world, warnings module is the most use way to do deprecation. Here are some arguments that where taken into account when deciding to use warnings module over logging:
-
When running normal (
python manage.py runserver 0.0.0.0:8000)- Logging deprecations ARE printed (every time they appear)
- Warnings deprecations are NOT printed.
-
When deprecation warnings enabled (
python -Wd manage.py runserver 0.0.0.0:8000)- Logging deprecations ARE printed. (every time they appear)
- Warnings deprecations ARE printed. (only printed ONCE, the first time it is emmited.)
-
When running tests (
pytest ...)- Logging deprecations ARE printed (when the test fails)
- Warnings deprecations ARE printed.
- Tests DO NOT FAIL!
-
When running tests and treating errors as warnings (
pytest -W error) This is what we are doing insentryrepo.- Logging deprecations ARE printed (when the test fails)
- Logging deprecations are NOT breaking the test run.
- Warnings deprecations ARE printed.
- Warnings deprecations ARE breaking the test run.
- Deprecation warnings from certain packages can be ignored by adding this to pytest.ini:
filterwarnings =
error ; turn warnings into errors
; ignore::DeprecationWarning:polls.* ; if users call deprecated sentry function from their code they also need to ignore depreactions from their module
ignore::DeprecationWarning:sentry_sdk.* ; ignore deprecations from sentry_sdkAll in all:
warningsare not shown in the default case (which is good, we do not want to annoy users)warningsare only emitted once (compared to logging, where every call will be logged, so warnings do not spam the users logs that muchwarningsare printed by default when running tests. This is OK.- There is fine grained settings for showing/hiding
warningsand also a lot of tooling supportswarnings.
sentrivana, szokeasaurusrex and sl0thentr0py