TST-52Recommended
Turn deprecation warnings into test failures
The test run fails on any deprecation warning from your own code or a dependency. Each warning you choose to ignore is listed with an issue link.
How to do it
Libraries warn a version or more before they remove a feature. The warnings scroll past in the test log, and the next update breaks the build or production. Make the test runner treat them as errors, such as filterwarnings = error in pytest or node --throw-deprecation for Node.js. When a dependency warns and no fix exists yet, ignore that one message by its text, with a link to the issue. Remove the ignore when the dependency is fixed. This keeps automatic dependency updates safe to merge.
Examples
TOML example
# pyproject.toml
[tool.pytest.ini_options]
filterwarnings = [
"error",
# https://github.com/example/shop/issues/412 until payments-sdk stops calling datetime.utcnow()
"ignore:datetime.datetime.utcnow:DeprecationWarning:payments_sdk",
]
JSON example
{
"scripts": {
"test": "node --throw-deprecation --test"
}
}
How to check
Add a call to a deprecated function in a test. The run fails. Every ignore entry in the test settings has a comment with an issue link.
Sources
Related rules
- Update dependencies in small automatic steps in Engineering
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/testing/test-quality/deprecations-fail-tests">Agent Wranglers testing playbook</a>. In code you write, add a comment next to it with the same link.