Skip to content

Fix caplog access during teardown report creation - #14812

Draft
scapalive wants to merge 1 commit into
pytest-dev:mainfrom
scapalive:forgeai/e9646c72
Draft

Fix caplog access during teardown report creation#14812
scapalive wants to merge 1 commit into
pytest-dev:mainfrom
scapalive:forgeai/e9646c72

Conversation

@scapalive

Copy link
Copy Markdown

Fixes #14436.

"LogCaptureFixture" now retains the logging handler and per-phase records mapping created for its test item, instead of retrieving them from "item.stash" on every access.

The logging plugin removes those stash entries at the end of teardown. However, teardown "pytest_runtest_makereport" consumers may still retain the fixture through "item.funcargs". Accessing "caplog.text" or "caplog.get_records()" at that point could therefore raise "KeyError".

The regression test covers both access paths during teardown report creation.

@psf-chronographer psf-chronographer Bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Jul 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided (automation) changelog entry is part of PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

caplog fixture raises KeyError

1 participant