When adding tests for new behavior, deprecations, or environment-dependent code paths, ensure the test actually exercises the intended branch (avoid vacuous passing) and assert the concrete observable effect.
Apply this checklist: 1) Force the guard conditions
from unittest.mock import MagicMock, patch
with patch.dict(
sys.modules,
{
'gevent': MagicMock(),
# add 'eventlet' similarly if needed
},
clear=False,
):
worker.on_start()
# assert warning/log behavior here
2) Test the user-visible outcome (not just “no crash”)
3) Choose the right level to avoid flakiness
4) Assert precisely
Following these rules prevents tests that “pass vacuously,” improves regression protection for behavior changes/deprecations, and keeps higher-level tests from becoming brittle.
Enter the URL of a public GitHub repository