Skip to content

Issue 14112#14397

Draft
evanwilson2123 wants to merge 6 commits intopytest-dev:mainfrom
evanwilson2123:issue-14112
Draft

Issue 14112#14397
evanwilson2123 wants to merge 6 commits intopytest-dev:mainfrom
evanwilson2123:issue-14112

Conversation

@evanwilson2123
Copy link
Copy Markdown

Summary

Handled an intermittent OSError: [Errno 5] Input/output error raised from _read_pyc during parallel collection with pytest-xdist.

The failure occurred when open(pyc, "rb") succeeded, but an OSError was raised from the file context-manager path (with fp: / __exit__). _read_pyc now treats that as a cache-read failure and returns None, matching existing cache-miss behavior.

Closes #14112.

What changed

  • Wrapped the with fp: block in _read_pyc with except OSError handling.
  • Kept trace logging for diagnosis.
  • Added a regression test:
    • test_read_pyc_handles_context_manager_oserror
    • Simulates open() success + context-manager OSError(errno.EIO) and asserts _read_pyc(...) is None.

Why this is correct

_read_pyc is a best-effort assertion-rewrite cache read path. Returning None on I/O failure is the intended cache-miss fallback and avoids hard-failing collection due to transient filesystem errors under parallel execution.

Validation

python3.12 -m pytest testing/test_assertrewrite.py -k "test_read_pyc_handles_context_manager_oserror" -q
python3.12 -m pytest testing/test_assertrewrite.py -k "read_pyc" -q
python3.12 -m pytest -n 8 testing/test_assertrewrite.py -k "read_pyc" -q

@psf-chronographer psf-chronographer bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Apr 19, 2026
@evanwilson2123 evanwilson2123 marked this pull request as draft April 19, 2026 15:12
@evanwilson2123 evanwilson2123 marked this pull request as ready for review April 19, 2026 15:14
@evanwilson2123 evanwilson2123 marked this pull request as draft April 19, 2026 15:15
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.

pytest crashing with ptest-xdist

2 participants