Fix session-end gc in unraisableexception plugin to respect warning filters#14273
Open
coder-jatin-s wants to merge 3 commits intopytest-dev:mainfrom
Open
Fix session-end gc in unraisableexception plugin to respect warning filters#14273coder-jatin-s wants to merge 3 commits intopytest-dev:mainfrom
coder-jatin-s wants to merge 3 commits intopytest-dev:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes ordering between the
unraisableexceptionandwarningsplugins so session-endgc.collect()runs while warning filters are still active.Fix #14263
Previously, the
unraisableexceptionplugin registered aconfig.add_cleanup()callback that runs severalgc.collect()rounds at session end. Becauseconfig.add_cleanup()uses a LIFOExitStack, and thewarningsplugin registers its cleanup afterunraisableexceptionindefault_plugins, the order at session teardown was:warningscleanup: tears down itscatch_warningscontext, sofilterwarnings = error::ResourceWarningfrompytest.inistops applying.unraisableexceptioncleanup: runsgc.collect(), finalizing unclosed resources whose__del__emitsResourceWarning.Those
ResourceWarnings were no longer affected by the configured warning filters and could be silently discarded instead of being turned into errors or reported viasys.unraisablehook.Implementation
pytest_unconfigureinunraisableexceptionto:gc_collect_harder(...)for the configured number of iterations.collect_unraisable(config)to process any unraisable exceptions.cleanupcallback to:sys.unraisablehookto the previous hook.unraisable_exceptionsstash entry.Because
pytest_unconfigureruns beforeConfig._cleanup_stack.close(),the final
gc.collect()calls now happen while the warnings plugin's filters(from
filterwarnings/-W) are still active.Testing
testing/test_unraisableexception.pytests.testing/test_warnings.pytests.filterwarnings = error::ResourceWarningnow causesleaked resources finalized at session end to be treated as errors.