Repository navigation
fix(test): reset item._request after a timeout escape - #37941
Conversation
When pytest-timeout's pytest.fail escapes pytest_runtest_protocol, the rootdir conftest's escape guard synthesizes the missing reports and runs teardown, but runtestprotocol's last step never ran: the item keeps its rebuilt TopRequest and funcargs. On the same xdist worker, test_no_collected_item_waits_with_a_request_built then fails beside the timed-out neighbour and blames collection. The guard now takes that step itself (item._request = False, item.funcargs = None), as runtestprotocol does, and a parametrized test drives each of its three branches with an item holding a request.
First Principles Review (Opus 5.5) — ⏭️ skippedRevision |
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: this is a test-harness-only change, and it adds the same request/funcargs cleanup that pytest's [DESIGN-REVIEWED] cc78fe1 Description read[DESCRIPTION-READ] f06f76a74542edfba36e27f4575bc70f41ba52d88076f12168587d6649175b7d That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
Code change approver recommendation: ApproveWhy: the decider estimates a 6% chance that this change introduces a defect, within the 12% limit for approving on its own, and every check passes. Small change to the test harness only. When a test times out and the failure escapes, the How I checked it:
An automated recommendation, not a review: a maintainer still decides. It approves on its own only when the estimated chance of a defect is at most 12% and the change has at most 400 changed lines. Decider v3c (217fe607) · commit |
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Tier 1 auto-approve: fix (2 files). Criteria: no conflict, no requested changes, security path denylist clean, design-doc gate clean, security checklist all-NO, no reviewer-lane findings, readiness signal fresh for this head SHA, declared category matches the diff. Category: test-harness fix; the xdist escaped-failure guard in conftest.py now drops the item's request and fixture values the way runtestprotocol would, with a parametrized test for it.
Problem / Motivation
Goal:
test/test_worker_memory_retention.pypasses on an xdist worker even after an earlier test on that worker timed out.test_no_collected_item_waits_with_a_request_built(added by #37814) asserts that no other collected item still holds a built_request. When pytest-timeout'spytest.failescapespytest_runtest_protocol, the rootdirconftest.pyescape guard writes the missing reports and runs teardown, but it never takesruntestprotocol's last step. The timed-out item keeps itsTopRequestandfuncargs, so the retention test then fails on that worker and blames collection. The same fix is already on the release PR #37884.Why it matters
Any timeout on a worker turns a second, unrelated test red. That makes
test_worker_memory_retention.pydepend on what ran before it, which breaks the tests-are-deterministic rule and sends readers after a collection bug that does not exist.Not a goal
What changed (motivation → approach → change)
The escape guard in
conftest.pyskips the stepruntestprotocolruns after every test. It now takes that step itself: when the item has a_request, it setsitem._request = Falseanditem.funcargs = None, the state pytest leaves behind. This is a cherry-pick of the second commit of #37884; main already has #37814.Backwards compatibility
Compatible: only the test harness changes, and it now leaves a timed-out item in the same state as every other finished item.
Removes nothing: the guard drops per-item request state that pytest itself drops after every normal test.
Tests
test/test_xdist_escaped_failure_guard.pygainstest_an_escape_drops_the_request_as_runtestprotocol_would, parametrized over the guard's three branches (no-call,no-teardown,all-logged). Each drives the guard with an item holding a request and checks the request and fixture values are gone.Proof: PROVEN test/test_xdist_escaped_failure_guard.py::test_an_escape_drops_the_request_as_runtestprotocol_would[no-call], test/test_xdist_escaped_failure_guard.py::test_an_escape_drops_the_request_as_runtestprotocol_would[no-teardown], test/test_xdist_escaped_failure_guard.py::test_an_escape_drops_the_request_as_runtestprotocol_would[all-logged] (head cc78fe1)
Determinism:
test/test_xdist_escaped_failure_guard.pypassed 5 repeats at-n 2(10 passed each).test/test_xdist_escaped_failure_guard.pyandtest/test_worker_memory_retention.pytogether passed in one shuffled order and its reverse at-n 0(24 passed, 1 skipped each).Manual verification
N/A -- the unit tests drive every branch of the changed guard.
Related Issues
Part of #37771
Follows #37814. Same fix as the second commit of #37884.
Sibling sweep
Swept: git grep -n "runtestprotocol|_request = False|funcargs = None" -- '*.py'
Sibling: conftest.py:709 -- not affected -- the item-collected hook already drops
_requestat collection timePattern harvest
Not generalizable: the escape guard is the one place that stands in for
runtestprotocol, and it now mirrors that function's final cleanup.Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)