Skip to content

fix: catch OSError in _read_pyc file read#14304

Open
themavik wants to merge 1 commit intopytest-dev:mainfrom
themavik:fix/14112-read-pyc-ioerror
Open

fix: catch OSError in _read_pyc file read#14304
themavik wants to merge 1 commit intopytest-dev:mainfrom
themavik:fix/14112-read-pyc-ioerror

Conversation

@themavik
Copy link

Summary

Fixes #14112.
Root cause: The file read operation in _read_pyc was outside the try/except block, so OSError during fp.read() was not caught. This caused crashes when using pytest-xdist, where concurrent file access can trigger I/O errors.
Fix: Moved the file read into the try/except block to properly catch OSError.

Changes

  • src/_pytest/assertion/rewrite.py: Moved with fp: into the try block

Testing

  • Verified fix catches OSError during pyc file reads
  • Change is minimal and follows existing error handling patterns

Made with Cursor

Root cause: The file read operation in _read_pyc was outside the
try/except block, so I/O errors during fp.read() were not caught,
causing crashes with pytest-xdist.

Made-with: Cursor
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.

pytest crashing with ptest-xdist

1 participant