Skip to content

Commit

Permalink
ensure log file cleanup as finalizer
Browse files Browse the repository at this point in the history
Signed-off-by: Jeffrey Martin <[email protected]>
  • Loading branch information
jmartin-tech committed Apr 26, 2024
1 parent d8bb303 commit 8ae224e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
23 changes: 18 additions & 5 deletions tests/cli/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,24 @@


@pytest.fixture(autouse=True)
def close_report_file():
if _config.transient.reportfile is not None:
_config.transient.reportfile.close()
if os.path.exists(_config.transient.report_filename):
os.remove(_config.transient.report_filename)
def cleanup(request):
"""Cleanup a testing and report directory once we are finished."""

def remove_log_files():
files = []
if _config.transient.reportfile is not None:
_config.transient.reportfile.close()
report_html_file = _config.transient.report_filename.replace(
".jsonl", ".html"
)
files.append(_config.transient.report_filename)
files.append(report_html_file)

for file in files:
if os.path.exists(file):
os.remove(file)

request.addfinalizer(remove_log_files)


def test_version_command(capsys):
Expand Down
4 changes: 4 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,11 @@ def remove_log_files():
]
if _config.transient.reportfile is not None:
_config.transient.reportfile.close()
report_html_file = _config.transient.report_filename.replace(
".jsonl", ".html"
)
files.append(_config.transient.report_filename)
files.append(report_html_file)

for file in files:
if os.path.exists(file):
Expand Down

0 comments on commit 8ae224e

Please sign in to comment.