Skip to content

tests: scope blanket os fakes so pytest 9.2 capture still works - #172

Merged
inxbit merged 1 commit into
mainfrom
tests/pytest-9.2-capture-safe-patches
Nov 5, 2026
Merged

inxbit merged 1 commit into
mainfrom
tests/pytest-9.2-capture-safe-patches

Conversation

@inxbit

@inxbit inxbit commented Nov 5, 2026

Copy link
Copy Markdown
Owner

Why

Dependabot PR #171 (python-tooling group) fails all 8 test jobs. Same 3 tests every time:

  • test_existing_special_device_rejects_identity_change
  • test_existing_special_device_rejects_fifo_owner_change_after_open
  • test_existing_special_device_rechecks_fifo_mode_on_the_opened_node

AttributeError: 'types.SimpleNamespace' object has no attribute 'st_size'

Root cause: pytest 9.2.0 FDCapture.snap() now calls os.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 replaced os.fstat, os.lstat, os.open and os.close globally 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. Other os.fstat patches 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:

Env Scope Result
PR #171 pins (pytest 9.2.0), Python 3.13 tests/test_export.py 64 passed, 2 skipped
PR #171 pins (pytest 9.2.0), Python 3.13 full suite 744 passed, 8 skipped
main pins (pytest 9.1.1) tests/test_export.py 64 passed, 2 skipped

Before the change, the same 9.2.0 env reproduced the CI failure.

ruff check . clean.

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.
@inxbit
inxbit merged commit 1141728 into main Nov 5, 2026
11 checks passed
@inxbit
inxbit deleted the tests/pytest-9.2-capture-safe-patches branch November 5, 2026 20:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant