Skip to content

Commit 60dc673

Browse files
gauravclaude
andcommitted
Close the --report-jsonl file when the session ends
pytest_configure opens it and nothing ever closed it; it was left to interpreter shutdown. Nothing is lost today, because every record is flush()ed as it is written — which is exactly what makes this worth fixing rather than shrugging at. The flush is per test phase on a file that gets thousands of them, so it is the obvious thing for someone to remove when this run feels slow, and the day that happens the last records of a run vanish with no error and the dashboard quietly under-reports. Noticed reviewing #120; not caused by it. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent 1d80ea0 commit 60dc673

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

tests/conftest.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,17 @@ def pytest_runtest_logreport(report):
130130
_report_file.flush()
131131

132132

133+
def pytest_unconfigure(config):
134+
# Closed explicitly rather than left to interpreter shutdown. Every line is
135+
# flushed as it is written, so nothing is lost today — but that makes this a
136+
# bug that only appears if someone ever drops the flush() for speed, which is
137+
# the obvious optimisation to reach for on a file written once per test phase.
138+
global _report_file
139+
if _report_file is not None:
140+
_report_file.close()
141+
_report_file = None
142+
143+
133144
def pytest_addoption(parser):
134145
# The target environment(s) to target.
135146
parser.addoption(

0 commit comments

Comments
 (0)