@@ -38,14 +38,21 @@ if(CMAKE_SCRIPT_MODE_FILE)
3838 list (JOIN EXTRA_ARGS_WRAPPED " " EXTRA_ARGS_STR)
3939
4040 # Macro to create individual tests with optional test properties.
41- macro (create_test NAME IDENTIFIER )
42- string (APPEND _content
43- "add_test([==[${NAME} ]==] \" ${PYTEST_EXECUTABLE} \" [==[${IDENTIFIER} ]==] ${EXTRA_ARGS_STR} )\n "
44- )
41+ macro (create_test NAME IDENTIFIERS )
42+ string (APPEND _content "add_test([==[${NAME} ]==] \" ${PYTEST_EXECUTABLE} \" " )
43+
44+ foreach (identifier ${IDENTIFIERS} )
45+ string (APPEND _content " [==[${identifier} ]==]" )
46+ endforeach ()
47+
48+ string (APPEND _content " ${EXTRA_ARGS_STR} )\n " )
4549
4650 # Prepare the properties for the test, including the environment settings.
4751 set (args "PROPERTIES ENVIRONMENT [==[${ENCODED_ENVIRONMENT} ]==]" )
4852
53+ # Add working directory
54+ string (APPEND args " WORKING_DIRECTORY [==[${WORKING_DIRECTORY} ]==]" )
55+
4956 # Append any additional properties, escaping complex characters if necessary.
5057 foreach (property ${TEST_PROPERTIES} )
5158 if (property MATCHES "[^-./:a-zA-Z0-9_]" )
@@ -61,27 +68,35 @@ if(CMAKE_SCRIPT_MODE_FILE)
6168
6269 # If tests are bundled together, create a single test group.
6370 if (BUNDLE_TESTS)
64- create_test ("\$ {TEST_GROUP_NAME}" "\$ {WORKING_DIRECTORY }" )
71+ create_test ("\$ {TEST_GROUP_NAME}" "\$ {TEST_PATHS }" )
6572
6673 else ()
6774 # Set environment variables for collecting tests.
6875 set (ENV{${LIBRARY_ENV_NAME} } "${LIBRARY_PATH} " )
6976 set (ENV{PYTHONPATH} "${PYTHON_PATH} " )
7077 set (ENV{PYTHONWARNINGS} "ignore" )
7178
79+ set (_command
80+ "${PYTEST_EXECUTABLE} " --collect-only -q
81+ "--rootdir=${WORKING_DIRECTORY} "
82+ ${DISCOVERY_EXTRA_ARGS}
83+ )
84+
85+ foreach (test_path IN LISTS TEST_PATHS)
86+ list (APPEND _command "${test_path} " )
87+ endforeach ()
88+
7289 # Collect tests.
7390 execute_process (
74- COMMAND "${PYTEST_EXECUTABLE} "
75- --collect-only -q
76- --rootdir=${WORKING_DIRECTORY} ${DISCOVERY_EXTRA_ARGS} .
91+ COMMAND ${_command}
7792 OUTPUT_VARIABLE _output_lines
7893 ERROR_VARIABLE _output_lines
7994 OUTPUT_STRIP_TRAILING_WHITESPACE
8095 WORKING_DIRECTORY ${WORKING_DIRECTORY}
8196 )
8297
8398 # Check for errors during test collection.
84- string (REGEX MATCH "=+ ERRORS =+(.*) " _error "${_output_lines} " )
99+ string (REGEX MATCH "( =+ ERRORS =+|ERROR:).* " _error "${_output_lines} " )
85100
86101 if (_error)
87102 message (${_error} )
@@ -141,7 +156,7 @@ if(CMAKE_SCRIPT_MODE_FILE)
141156
142157 # Prefix the test name with the test group name.
143158 set (test_name "${TEST_GROUP_NAME} .${test_name} " )
144- set (test_case "${WORKING_DIRECTORY} / ${ line} " )
159+ set (test_case "${line} " )
145160
146161 # Create the test for CTest.
147162 create_test ("\$ {test_name}" "\$ {test_case}" )
0 commit comments