From 90dddfa7a40a7aface92bfb097a95412bdcb1be8 Mon Sep 17 00:00:00 2001 From: Zxilly Date: Thu, 11 Jul 2024 20:19:07 +0800 Subject: [PATCH] test: fix temp file race on Windows Signed-off-by: Zxilly --- scripts/tool/merge.py | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/scripts/tool/merge.py b/scripts/tool/merge.py index a0ee066dde..2e420d7400 100644 --- a/scripts/tool/merge.py +++ b/scripts/tool/merge.py @@ -32,8 +32,11 @@ def merge_covdata_dir(d: str, output: str): if os.path.exists(output): os.remove(output) - tmp_out = tempfile.NamedTemporaryFile(delete=False) - if not dir_is_empty(d): + if dir_is_empty(d): + log(f"Coverage data directory is empty. Skipping merge {output}") + return + + with tempfile.NamedTemporaryFile(delete=False) as tmp: subprocess.check_call( [ require_go(), @@ -41,22 +44,14 @@ def merge_covdata_dir(d: str, output: str): "covdata", "textfmt", "-i=" + d, - "-o=" + tmp_out.name, + "-o=" + tmp.name, ], cwd=get_project_root(), ) - log(f"Merged coverage data from {d}.") - - enhance_coverage(tmp_out.name, output) - + enhance_coverage(tmp.name, output) log(f"Enhanced coverage data from {d}.") - os.remove(tmp_out.name) - - log(f"Merge cleaned up for {d}.") - else: - log(f"Coverage data directory is empty. Skipping merge {output}") merge_covdata_dir(get_covdata_unit_dir(), "unit.profile") merge_covdata_dir(get_covdata_integration_dir(), "integration.profile")