@@ -11,18 +11,37 @@ set(EXCLUDED_TESTS
1111 "test_ops_roi_align.py" "test_tensor_fill_diagonal_tensor_op_iluvatar.py"
1212 "test_tensor_fill_diagonal_op_iluvatar.py" "test_bincount_op_iluvatar.py" )
1313
14- list (JOIN EXCLUDED_TESTS " or " EXCLUDE_EXPR)
15- set (K_FILTER "not (${EXCLUDE_EXPR} )" )
16-
17- add_test (
18- NAME pytest_main
19- COMMAND ${Python_EXECUTABLE} -m pytest ${CMAKE_SOURCE_DIR } /unittests/ -k
20- ${K_FILTER} --tb=short -v
21- WORKING_DIRECTORY ${CMAKE_SOURCE_DIR } )
22-
23- set_tests_properties (
24- pytest_main
25- PROPERTIES
26- ENVIRONMENT "PYTHONPATH=${LEGACY_TEST_PATH} :$ENV{PYTHONPATH} "
27- "LD_PRELOAD=${LD_LIBRARY_PATH} /libcuda.so.1"
28- "CUSTOM_DEVICE_ROOT=${CMAKE_BINARY_DIR } /python/paddle_custom_device/" )
14+ # Find all test files
15+ file (GLOB TEST_FILES "${CMAKE_SOURCE_DIR } /unittests/test_*.py" )
16+
17+ # Create a separate CTest test for each test file
18+ foreach (TEST_FILE ${TEST_FILES} )
19+ get_filename_component (TEST_NAME ${TEST_FILE} NAME )
20+
21+ # Check if it's in the exclusion list
22+ set (IS_EXCLUDED FALSE )
23+ foreach (EXCLUDED_TEST ${EXCLUDED_TESTS} )
24+ if (TEST_NAME STREQUAL EXCLUDED_TEST)
25+ set (IS_EXCLUDED TRUE )
26+ break ()
27+ endif ()
28+ endforeach ()
29+
30+ # If not in the exclusion list, add the test
31+ if (NOT IS_EXCLUDED)
32+ # Get the filename without extension as the test name
33+ get_filename_component (TEST_BASE_NAME ${TEST_FILE} NAME_WE )
34+
35+ add_test (
36+ NAME ${TEST_BASE_NAME}
37+ COMMAND ${Python_EXECUTABLE} -m pytest ${TEST_FILE} --tb=short
38+ WORKING_DIRECTORY ${CMAKE_SOURCE_DIR } )
39+
40+ set_tests_properties (
41+ ${TEST_BASE_NAME}
42+ PROPERTIES
43+ ENVIRONMENT "PYTHONPATH=${LEGACY_TEST_PATH} :$ENV{PYTHONPATH} "
44+ "LD_PRELOAD=${LD_LIBRARY_PATH} /libcuda.so.1"
45+ "CUSTOM_DEVICE_ROOT=${CMAKE_BINARY_DIR } /python/paddle_custom_device/" )
46+ endif ()
47+ endforeach ()
0 commit comments