Skip to content

Comments

Fix nested caplog.filtering with same filter object#14228

Open
elpolini wants to merge 1 commit intopytest-dev:mainfrom
elpolini:fix/caplog-nested-filtering-14189
Open

Fix nested caplog.filtering with same filter object#14228
elpolini wants to merge 1 commit intopytest-dev:mainfrom
elpolini:fix/caplog-nested-filtering-14189

Conversation

@elpolini
Copy link

@elpolini elpolini commented Feb 22, 2026

Summary

  • Fix caplog.filtering so nested use with the same filter object does not remove the outer filter too early.
  • Only add/remove the filter when this context manager actually changed handler state.
  • Add a regression test for nested caplog.filtering with the same filter instance.

Why

Issue #14189 reports that nested caplog.filtering can unexpectedly remove an active filter, causing logs to leak into capture inside the outer context.

Validation

  • python -m pytest -q testing/logging/test_fixture.py -k with_statement_filtering

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant