-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix ValueError: I/O operation on closed file during tests #123
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #123 +/- ##
==========================================
+ Coverage 83.72% 83.76% +0.04%
==========================================
Files 34 34
Lines 3403 3413 +10
==========================================
+ Hits 2849 2859 +10
Misses 554 554
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
This sadly didn't fix the issue :( Will leave this PR in Draft state for more adhoc tests. |
Took a while but this should now be fixed. I took quite a deep dive into the pytest internals to figure out the cause. It's mainly caused due to pytest's capture.py swapping The easiest fix was to ensure that when we request a stdout stream in I have no idea why this only happened on PyPy. Could be a race condition. |
Co-authored-by: Erik Schamper <[email protected]>
Sometimes the
stdout
file object is closed byflow.record
internals as it is sometimes mocked and swapped bypytest
during tests which in turn can confuseis_stdout()
to returnFalse
causing the file to be closed.This is now fixed by adding two custom methods for getting the stdio streams:
flow.record.utils.get_stdout()
flow.record.utils.get_stdin()
These methods are the preferred way to get the stdio streams as they also set an extra attribute on the returned file object that is checked by
is_stdout()
.