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 25, 2024
1 parent a36e276 commit dea3b0f
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 @@ -482,7 +482,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 dea3b0f

Please sign in to comment.