diff --git a/test/xpu/extended/run_test_with_skip.py b/test/xpu/extended/run_test_with_skip.py index 9c7b2270f..748902f6f 100644 --- a/test/xpu/extended/run_test_with_skip.py +++ b/test/xpu/extended/run_test_with_skip.py @@ -1,4 +1,5 @@ import os +import pytest import sys from skip_list_common import skip_dict from skip_list_win import skip_dict as skip_dict_win @@ -9,14 +10,12 @@ if IS_WINDOWS: skip_list += skip_dict_win["test_ops_xpu.py"] -skip_options = " -k \"not " + skip_list[0] +skip_options = "not " + skip_list[0] for skip_case in skip_list[1:]: skip_option = " and not " + skip_case skip_options += skip_option -skip_options += "\"" os.environ["PYTORCH_TEST_WITH_SLOW"]="1" -test_command = "pytest -v test_ops_xpu.py" -test_command += skip_options -res = os.system(test_command) +test_command = ["-k", skip_options, "test_ops_xpu.py", "-v"] +res = pytest.main(test_command) sys.exit(res) diff --git a/test/xpu/extended/run_test_with_skip_arc.py b/test/xpu/extended/run_test_with_skip_arc.py index 30fd2c0e0..85ea0b643 100644 --- a/test/xpu/extended/run_test_with_skip_arc.py +++ b/test/xpu/extended/run_test_with_skip_arc.py @@ -1,4 +1,5 @@ import os +import pytest import sys from skip_list_common import skip_dict from skip_list_arc import skip_dict as skip_dict_specifical @@ -11,14 +12,12 @@ if IS_WINDOWS: skip_list += skip_dict_win["test_ops_xpu.py"] + skip_dict_win_arc["test_ops_xpu.py"] -skip_options = " -k \"not " + skip_list[0] +skip_options = "not " + skip_list[0] for skip_case in skip_list[1:]: skip_option = " and not " + skip_case skip_options += skip_option -skip_options += "\"" os.environ["PYTORCH_TEST_WITH_SLOW"]="1" -test_command = "pytest -v test_ops_xpu.py" -test_command += skip_options -res = os.system(test_command) +test_command = ["-k", skip_options, "test_ops_xpu.py", "-v"] +res = pytest.main(test_command) sys.exit(res) \ No newline at end of file diff --git a/test/xpu/xpu_test_utils.py b/test/xpu/xpu_test_utils.py index 1d18a27e2..23d3308ca 100644 --- a/test/xpu/xpu_test_utils.py +++ b/test/xpu/xpu_test_utils.py @@ -3,6 +3,7 @@ import copy import os +import pytest import sys import unittest @@ -1037,30 +1038,26 @@ def launch_test(test_case, skip_list=None, exe_list=None): os.environ["PYTORCH_ENABLE_XPU_FALLBACK"]="1" os.environ["PYTORCH_TEST_WITH_SLOW"]="1" if skip_list != None: - skip_options = " -k \"not " + skip_list[0] + skip_options = "not " + skip_list[0] for skip_case in skip_list[1:]: skip_option = " and not " + skip_case skip_options += skip_option - skip_options += "\"" - test_command = ( - "pytest -v " - + test_case - ) - test_command += skip_options + if test_case == "test_dataloader_xpu.py": + test_command = ["-k", skip_options, "-n", "1", test_case, "-v"] + else: + test_command = ["-k", skip_options, test_case, "-v"] elif exe_list != None: - exe_options = " -k \"" + exe_list[0] + exe_options = exe_list[0] for exe_case in exe_list[1:]: exe_option = " or " + exe_case exe_options += exe_option - exe_options += "\"" - test_command = ( - "pytest -v " - + test_case - ) - test_command += exe_options + if test_case == "test_dataloader_xpu.py": + test_command = ["-k", exe_options, "-n", "1", test_case, "-v"] + else: + test_command = ["-k", exe_options, test_case, "-v"] else: - test_command = ( - "pytest -v " - + test_case - ) - return os.system(test_command) + if test_case == "test_dataloader_xpu.py": + test_command = ["-n", "1", test_case, "-v"] + else: + test_command = [test_case, "-v"] + return pytest.main(test_command)