Skip to content

Commit

Permalink
ensure cleanup of test run log files
Browse files Browse the repository at this point in the history
* shift fixture execution to a finalizer
* remove `html` and `josonl` files

Signed-off-by: Jeffrey Martin <[email protected]>
  • Loading branch information
jmartin-tech committed Apr 19, 2024
1 parent 90a258f commit d28b021
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
16 changes: 11 additions & 5 deletions tests/cli/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@


@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):
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)
html_file = _config.transient.report_filename.replace(".jsonl", ".html")
if os.path.exists(html_file):
os.remove(html_file)

request.addfinalizer(close_report_file)


def test_version_command(capsys):
Expand Down
1 change: 1 addition & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,7 @@ def remove_log_files():
if _config.transient.reportfile is not None:
_config.transient.reportfile.close()
files.append(_config.transient.report_filename)
files.append(_config.transient.report_filename.replace(".jsonl", ".html"))

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

0 comments on commit d28b021

Please sign in to comment.