From 095f47593d233565ac35ad8dfa60f6c2b23fa30b Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Mon, 26 Jun 2023 20:37:55 -0700 Subject: [PATCH] run unit tests inside docker for safety --- {scripts => benchmark}/benchmark.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) rename {scripts => benchmark}/benchmark.py (95%) diff --git a/scripts/benchmark.py b/benchmark/benchmark.py similarity index 95% rename from scripts/benchmark.py rename to benchmark/benchmark.py index fa83ae868..aa9ed8f75 100755 --- a/scripts/benchmark.py +++ b/benchmark/benchmark.py @@ -80,7 +80,8 @@ def main( dest = dirname.parent / "OLD" / dirname.name if dest.exists(): - dest = dirname.parent / "OLD" / (now + dirname.name) + old_now = datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S") + dest = dirname.parent / "OLD" / (old_now + dirname.name) dirname.rename(dest) @@ -351,9 +352,25 @@ def run_unit_tests(testdir, history_fname): timeout = 60 for test_file in test_files: dump(test_file) + + command = [ + "docker", + "run", + "-it", + "--rm", + "--interactive=false", + "-v", + f"{test_file.parent.absolute()}:/app", + "benchmark", + "bash", + "-c", + f"pip install pytest && pytest /app/{test_file.name}", + ] + print(" ".join(command)) + try: result = subprocess.run( - ["docker", "run", "--rm", "-v", f"{test_file}:/app/{test_file.name}", "python:3.8", "python", f"/app/{test_file.name}"], + command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True,