From ef07d17a978ef31df8b0ac227434a537baa3825b Mon Sep 17 00:00:00 2001 From: Cheng Penghui Date: Tue, 5 Nov 2024 02:35:57 +0000 Subject: [PATCH 1/4] Calling pytest from python code since skip list too long Signed-off-by: Cheng Penghui --- test/xpu/extended/run_test_with_skip.py | 9 ++++--- test/xpu/extended/run_test_with_skip_arc.py | 9 ++++--- test/xpu/xpu_test_utils.py | 26 ++++++--------------- 3 files changed, 15 insertions(+), 29 deletions(-) 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 c2c919da1..1d86f8b83 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 @@ -1019,30 +1020,17 @@ 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 + 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 + test_command = ["-k", exe_options, test_case, "-v"] else: - test_command = ( - "pytest -v " - + test_case - ) - return os.system(test_command) + test_command = [test_case, "-v"] + return pytest.main(test_command) From 8665dcc47d2938a006efe330b06a2889fb2e9e0b Mon Sep 17 00:00:00 2001 From: Cheng Penghui Date: Thu, 28 Nov 2024 06:12:35 +0000 Subject: [PATCH 2/4] Avoid multi-process since it will lead to error Signed-off-by: Cheng Penghui --- test/xpu/xpu_test_utils.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/xpu/xpu_test_utils.py b/test/xpu/xpu_test_utils.py index 0a335d896..c5155109e 100644 --- a/test/xpu/xpu_test_utils.py +++ b/test/xpu/xpu_test_utils.py @@ -1036,13 +1036,13 @@ def launch_test(test_case, skip_list=None, exe_list=None): for skip_case in skip_list[1:]: skip_option = " and not " + skip_case skip_options += skip_option - test_command = ["-k", skip_options, test_case, "-v"] + test_command = ["-k", skip_options, "-n", "1", test_case, "-v"] elif exe_list != None: exe_options = exe_list[0] for exe_case in exe_list[1:]: exe_option = " or " + exe_case exe_options += exe_option - test_command = ["-k", exe_options, test_case, "-v"] + test_command = ["-k", exe_options, "-n", "1", test_case, "-v"] else: - test_command = [test_case, "-v"] + test_command = ["-n", "1", test_case, "-v"] return pytest.main(test_command) From 71210eeb88bae5d5d19b8a0b2e805334dbe89add Mon Sep 17 00:00:00 2001 From: Cheng Penghui Date: Thu, 28 Nov 2024 06:16:44 +0000 Subject: [PATCH 3/4] Fixed typo Signed-off-by: Cheng Penghui --- test/xpu/xpu_test_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/xpu/xpu_test_utils.py b/test/xpu/xpu_test_utils.py index 303e3482c..c6ea9e1f9 100644 --- a/test/xpu/xpu_test_utils.py +++ b/test/xpu/xpu_test_utils.py @@ -1047,5 +1047,5 @@ def launch_test(test_case, skip_list=None, exe_list=None): exe_options += exe_option test_command = ["-k", exe_options, "-n", "1", test_case, "-v"] else: - test_command = ["-n", "1", test_case, "-v"] + test_command = ["-n", "1", test_case, "-v"] return pytest.main(test_command) From 415e84209853a2ce67afa2a8b616b5e05e13cf75 Mon Sep 17 00:00:00 2001 From: Cheng Penghui Date: Thu, 28 Nov 2024 06:59:31 +0000 Subject: [PATCH 4/4] Only limit multi-process on test_dataloader cases Signed-off-by: Cheng Penghui --- test/xpu/xpu_test_utils.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/test/xpu/xpu_test_utils.py b/test/xpu/xpu_test_utils.py index c6ea9e1f9..f8226b7b3 100644 --- a/test/xpu/xpu_test_utils.py +++ b/test/xpu/xpu_test_utils.py @@ -1039,13 +1039,22 @@ def launch_test(test_case, skip_list=None, exe_list=None): for skip_case in skip_list[1:]: skip_option = " and not " + skip_case skip_options += skip_option - test_command = ["-k", skip_options, "-n", "1", test_case, "-v"] + 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 = exe_list[0] for exe_case in exe_list[1:]: exe_option = " or " + exe_case exe_options += exe_option - test_command = ["-k", exe_options, "-n", "1", test_case, "-v"] + 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 = ["-n", "1", test_case, "-v"] + 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)