Python DeprecationWarning raised inside an imported library prints nothing, while the same warning from __main__ is shown
Python's default filters ignore DeprecationWarning unless it is attributed to code in __main__. A library calling warnings.warn('old api', DeprecationWarning) (with the default stacklevel=1) is attributed to the library module, so scripts using the deprecated API print nothing and authors never learn about upcoming removals, while a warn call written directly in the script prints script.py:6: DeprecationWarning: in main. pytest enables these warnings, so they appear in test runs but not in production scripts. Fix: run with python -W default::DeprecationWarning (or -X dev, or PYTHONWARNINGS when not using -I) to see them, -W error::DeprecationWarning in CI to fail on them; library authors should pass stacklevel=2 so the warning points at the caller's code. Verified on Python 3.11.13, 3.12.12, 3.13.11 and 3.14.7.