From d28b021a3729dcb2fccf82dbab56c421edacdee0 Mon Sep 17 00:00:00 2001 From: Jeffrey Martin Date: Fri, 19 Apr 2024 13:43:24 -0500 Subject: [PATCH] ensure cleanup of test run log files * shift fixture execution to a finalizer * remove `html` and `josonl` files Signed-off-by: Jeffrey Martin --- tests/cli/test_cli.py | 16 +++++++++++----- tests/test_config.py | 1 + 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/tests/cli/test_cli.py b/tests/cli/test_cli.py index 86bd08eab..f72d83312 100644 --- a/tests/cli/test_cli.py +++ b/tests/cli/test_cli.py @@ -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): diff --git a/tests/test_config.py b/tests/test_config.py index 7966d49a9..cac672df5 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -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):