Fix nested caplog.filtering with same filter object by elpolini · Pull Request #14228 · pytest-dev/pytest

Skip to content

Navigation Menu

Sign in

Appearance settings

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Appearance settings

Conversation

@elpolini

Copy link

@elpolini elpolini commented

Feb 22, 2026

edited

Loading

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

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

1 participant

@elpolini