|
24 | 24 | import os |
25 | 25 | import statistics |
26 | 26 | from pathlib import Path |
| 27 | +from tempfile import TemporaryDirectory |
27 | 28 | from typing import Callable, List, Optional, TypeVar |
28 | 29 |
|
29 | 30 | import scipy |
@@ -82,19 +83,20 @@ def git_ab_test( |
82 | 83 | (alternatively, your comparator can perform any required assertions and not return anything). |
83 | 84 | """ |
84 | 85 |
|
85 | | - dir_a = git_clone(Path("../build") / a_revision, a_revision) |
86 | | - result_a = test_runner(dir_a, True) |
| 86 | + with TemporaryDirectory() as tmp_dir: |
| 87 | + dir_a = git_clone(Path(tmp_dir) / a_revision, a_revision) |
| 88 | + result_a = test_runner(dir_a, True) |
87 | 89 |
|
88 | | - if b_revision: |
89 | | - dir_b = git_clone(Path("../build") / b_revision, b_revision) |
90 | | - else: |
91 | | - # By default, pytest execution happens inside the `tests` subdirectory. Pass the repository root, as |
92 | | - # documented. |
93 | | - dir_b = Path.cwd().parent |
94 | | - result_b = test_runner(dir_b, False) |
| 90 | + if b_revision: |
| 91 | + dir_b = git_clone(Path(tmp_dir) / b_revision, b_revision) |
| 92 | + else: |
| 93 | + # By default, pytest execution happens inside the `tests` subdirectory. Pass the repository root, as |
| 94 | + # documented. |
| 95 | + dir_b = Path.cwd().parent |
| 96 | + result_b = test_runner(dir_b, False) |
95 | 97 |
|
96 | | - comparison = comparator(result_a, result_b) |
97 | | - return result_a, result_b, comparison |
| 98 | + comparison = comparator(result_a, result_b) |
| 99 | + return result_a, result_b, comparison |
98 | 100 |
|
99 | 101 |
|
100 | 102 | DEFAULT_A_DIRECTORY = FC_WORKSPACE_DIR / "build" / "main" |
@@ -266,8 +268,6 @@ def git_clone(clone_path, commitish): |
266 | 268 | utils.check_output(f"git branch {branch_name} {commitish}") |
267 | 269 | _, git_root, _ = utils.run_cmd("git rev-parse --show-toplevel") |
268 | 270 | # split off the '\n' at the end of the stdout |
269 | | - utils.check_output( |
270 | | - f"git clone -b {branch_name} {git_root.strip()} {clone_path}" |
271 | | - ) |
| 271 | + utils.check_output(f"git clone -b {branch_name} {git_root.strip()} {clone_path}") |
272 | 272 | utils.check_output(f"git branch -D {branch_name}") |
273 | 273 | return clone_path |
0 commit comments