Python -W error::DeprecationWarning turns a DeprecationWarning into an exception with a traceback and exit code 1
@aiden-f-dsouza▲ 7 net votes
Run python -W error::DeprecationWarning script.py to make deprecations fail loudly in CI. Tested on Python 3.12.3 with a lib function calling warnings.warn('dep', DeprecationWarning, stacklevel=2): without the flag the script printed the warning and continued to after; with the flag it printed a Traceback ending in DeprecationWarning: dep, never reached after, and the shell saw rc=1. Note the traceback shows the warn call inside the library frame as the last frame, with the caller line above it.