Repository navigation
tests: scope blanket os fakes so pytest 9.2 capture still works - #172
Merged
Merged
Conversation
pytest 9.2.0 FDCapture.snap() calls os.fstat(tmpfile).st_size after the test body returns and before fixture teardown. Three export tests replaced os.fstat (and os.lstat, os.open, os.close) for the whole call phase with fakes that have no st_size, so pytest's own capture crashed with AttributeError on every CI job of the dependabot python-tooling PR #171. Apply those fakes inside monkeypatch.context() so they are undone before the test returns. Assertions are unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Dependabot PR #171 (python-tooling group) fails all 8 test jobs. Same 3 tests every time:
test_existing_special_device_rejects_identity_changetest_existing_special_device_rejects_fifo_owner_change_after_opentest_existing_special_device_rechecks_fifo_mode_on_the_opened_nodeAttributeError: 'types.SimpleNamespace' object has no attribute 'st_size'Root cause: pytest 9.2.0
FDCapture.snap()now callsos.fstat(self.tmpfile.fileno()).st_size(_pytest/capture.py:595). That runs in the call-phase hook wrapper, after the test body and before fixture teardown. These tests replacedos.fstat,os.lstat,os.openandos.closeglobally with fakes, so pytest read its own capture file through the fake.Change
Apply the fakes inside
monkeypatch.context()so they are undone before the test returns. Assertions unchanged. Otheros.fstatpatches in the file pass through to the real call for unrelated descriptors and are unaffected.Verification
CI on this PR runs main's pins (pytest 9.1.1), where the old tests also pass, so green CI here is not the proof. Local runs:
tests/test_export.pytests/test_export.pyBefore the change, the same 9.2.0 env reproduced the CI failure.
ruff check .clean.