Skip to content

Commit

Permalink
Properly close all streams
Browse files Browse the repository at this point in the history
  • Loading branch information
SvenDS9 committed Mar 9, 2023
1 parent e59cf64 commit 31573fe
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions test/test_prototype_datasets_builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,15 @@ def log_session_streams(self):
@parametrize_dataset_mocks(DATASET_MOCKS)
def test_stream_closing(self, log_session_streams, dataset_mock, config):
def make_msg_and_close(head):
unclosed_stream_reprs = []
unclosed_streams = []
for stream in StreamWrapper.session_streams.keys():
unclosed_streams.append(repr(stream.file_obj))
unclosed_stream_reprs.append(repr(stream.file_obj))
unclosed_streams.append(stream)
for stream in unclosed_streams:
stream.close()
unclosed_streams = "\n".join(unclosed_streams)
return f"{head}\n\n{unclosed_streams}"
unclosed_stream_reprs = "\n".join(unclosed_stream_reprs)
return f"{head}\n\n{unclosed_stream_reprs}"

if StreamWrapper.session_streams:
raise pytest.UsageError(make_msg_and_close("A previous test did not close the following streams:"))
Expand Down

0 comments on commit 31573fe

Please sign in to comment.