From d68b3b607cfa089b072b962cbf3549c86ef4778e Mon Sep 17 00:00:00 2001 From: Jeffrey Martin Date: Tue, 23 Apr 2024 16:26:08 -0500 Subject: [PATCH] retrieve executable from runtime * avoid hard coded executbale path by asking runtime path * guard file removal during cleanup Signed-off-by: Jeffrey Martin --- tests/analyze/test_analyze.py | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/tests/analyze/test_analyze.py b/tests/analyze/test_analyze.py index bbe9ce74b..1d55af306 100644 --- a/tests/analyze/test_analyze.py +++ b/tests/analyze/test_analyze.py @@ -3,6 +3,7 @@ import os import subprocess +import sys import pytest @@ -18,7 +19,12 @@ def garak_tiny_run() -> None: def test_analyze_log_runs(): result = subprocess.run( - ["python3", "-m", "garak.analyze.analyze_log", temp_prefix + ".report.jsonl"], + [ + sys.executable, + "-m", + "garak.analyze.analyze_log", + temp_prefix + ".report.jsonl", + ], check=True, ) assert result.returncode == 0 @@ -26,7 +32,12 @@ def test_analyze_log_runs(): def test_report_digest_runs(): result = subprocess.run( - ["python3", "-m", "garak.analyze.report_digest", temp_prefix + ".report.jsonl"], + [ + sys.executable, + "-m", + "garak.analyze.report_digest", + temp_prefix + ".report.jsonl", + ], check=True, ) assert result.returncode == 0 @@ -37,7 +48,14 @@ def cleanup(request): """Cleanup a testing directory once we are finished.""" def remove_logs(): - os.remove(temp_prefix + ".report.jsonl") - os.remove(temp_prefix + ".report.html") + logs = [ + temp_prefix + ".report.jsonl", + temp_prefix + ".report.html", + ] + for file in logs: + try: + os.remove(file) + except FileNotFoundError: + pass request.addfinalizer(remove_logs)