pytest-dev / pytest-dev/pytest
warnings: warning filters set by collected code during collection have no effect during test run
@RonnyPfannschmidt is already working on this.
Since Jul 26, 2025.
- Dominant language
- Python
- Stars
- 14.5k
- Forks
- 3.4k
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 35
Description
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 1a9d913ee1f9d1a56448f659649c96214f6d9645. 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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.