diff --git a/thunder/tests/test_dynamo.py b/thunder/tests/test_dynamo.py index 8f8feca0ab..4bcd2333f4 100644 --- a/thunder/tests/test_dynamo.py +++ b/thunder/tests/test_dynamo.py @@ -2,7 +2,8 @@ import warnings import itertools import os -from subprocess import run +import subprocess +import sys import torch import torch.fx import torch.nn as nn @@ -819,12 +820,16 @@ def func(x): s2 = f"{tmp_path}/graph1_thunder_0.py" assert os.path.exists(s1) assert os.path.exists(s2) - cmd = "pytest" if use_pytest_benchmark else "python" - result1 = run([cmd, s1], capture_output=True, text=True) - result2 = run([cmd, s2], capture_output=True, text=True) + cmd = [sys.executable] + if use_pytest_benchmark: + cmd = cmd + ["-m", "pytest"] + cmd1 = cmd + [s1] + cmd2 = cmd + [s2] + result1 = subprocess.run(cmd1, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True) + result2 = subprocess.run(cmd2, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True) - assert result1.returncode == 0, f"Reproducer {s1} failed with return code {result1.returncode}" - assert result2.returncode == 0, f"Reproducer {s2} failed with return code {result2.returncode}" + assert result1.returncode == 0, f"Reproducer {s1} failed: {result1}" + assert result2.returncode == 0, f"Reproducer {s2} failed: {result2}" @requiresCUDA @@ -852,9 +857,12 @@ def forward(self, x): s1 = f"{tmp_path}/graph0_thunder_0.py" assert os.path.exists(s1) - cmd = "pytest" if use_pytest_benchmark else "python" - result1 = run([cmd, s1], capture_output=True, text=True) - assert result1.returncode == 0, f"Reproducer {s1} failed with return code {result1.returncode}" + cmd = [sys.executable] + if use_pytest_benchmark: + cmd = cmd + ["-m", "pytest"] + cmd1 = cmd + [s1] + result1 = subprocess.run(cmd1, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True) + assert result1.returncode == 0, f"Reproducer {s1} failed: {result1}" def test_deepcopy_graph_module(): @@ -909,13 +917,16 @@ def func(x): def check(file_name, cmd): assert os.path.exists(file_name) - result = run([cmd, file_name], capture_output=True, text=True) - assert result.returncode == 0, f"Reproducer {file_name} failed with return code {result.returncode}" + cmd = cmd + [file_name] + result = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True) + assert result.returncode == 0, f"Reproducer {file_name} failed: {result}" s1 = f"{tmp_path}/graph0_thunder_0.py" s2 = f"{tmp_path}/graph0_thunder_2.py" s3 = f"{tmp_path}/graph0_thunder_4.py" - cmd = "pytest" if use_pytest_benchmark else "python" + cmd = [sys.executable] + if use_pytest_benchmark: + cmd = cmd + ["-m", "pytest"] for fname in [s1, s2, s3]: check(fname, cmd)