Skip to content

Fix caplog access during teardown report creation - #14812

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

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
@scapalive
scapalive marked this pull request as ready for review August 1, 2026 14:22
@scapalive

Copy link
Copy Markdown
Author

The failing "build (ubuntu-py311)" job appears unrelated to this change.

I reproduced the relevant tests locally on the PR HEAD ("f129e232f459b7ecb9b4e85ef69f70f0fd62d832"):

  • "TestPDB::test_pdb_unittest_postmortem": 30/30 runs passed
  • caplog regression test: passed
  • complete "testing/logging/test_fixture.py" and "testing/test_debugging.py" suites: 82 passed, 1 skipped, 6 xpassed

The PDB test does not use "caplog", so "LogCaptureFixture" is not instantiated in that path. I could not reproduce the timeout or identify a causal connection with this patch. The same commit also had a previous successful CI run.

Could a maintainer please rerun the failed job?

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