Skip to content

warnings: warning filters set by collected code during collection have no effect during test run #13485

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
bluetech opened this issue Jun 3, 2025 · 0 comments
Labels
plugin: warnings related to the warnings builtin plugin type: bug problem that needs to be addressed type: selftests a problem in the tests of pytest

Comments

@bluetech
Copy link
Member

bluetech commented Jun 3, 2025

In 2017 there was an issue #2430 complaining that module-level calls to warnings.filterwarnings are getting reset by pytest and thus have no effect. PR #2445 added a fix for this and a test testing/test_warnings.py::test_works_with_filterwarnings (still present).

In 2018 there was a change to add warning capture during collection 1a9d913. This means collection is now wrapped in a with warnings.catch_warnings and so all warnings.filterwarnings get reset after collection, regressing the issue #2430.

The tests continued to pass due to how it was written, however running pytest with -Wdefault causes it to (correctly) fail (see #13480).

Since we haven't received any complaints since it regressed, and a fix I think would be difficult, IMO we should just delete the test, basically WONTFIXing #2430.

@bluetech bluetech added type: bug problem that needs to be addressed plugin: warnings related to the warnings builtin plugin type: selftests a problem in the tests of pytest labels Jun 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugin: warnings related to the warnings builtin plugin type: bug problem that needs to be addressed type: selftests a problem in the tests of pytest
Projects
None yet
Development

No branches or pull requests

1 participant