Closed yunzheng closed 3 months ago
All modified and coverable lines are covered by tests :white_check_mark:
Project coverage is 83.76%. Comparing base (
0865b50
) to head (ca4f7e1
).
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
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 sys.stdout
with it's own objects (which is fine btw), however in our own code we check the file objects by comparing them to sys.stdout
or sys.stdout.buffer
, but as sys.stdout
keeps getting swapped multiple times (eg: nested pytest operations/fixtures) it could be that a file object that was once a sys.stdout
file is now not seen as stdout anymore, and therefore closed by flow.record
internals at certain points.
The easiest fix was to ensure that when we request a stdout stream in flow.record
to mark them as stdout
ourselves, and ensure that they don't get closed.
I have no idea why this only happened on PyPy. Could be a race condition.
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()
.