pytest-cmake 0.5.1__tar.gz → 0.11.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pytest_cmake-0.5.1 → pytest_cmake-0.11.0}/PKG-INFO +10 -7
- {pytest_cmake-0.5.1 → pytest_cmake-0.11.0}/README.md +5 -6
- {pytest_cmake-0.5.1 → pytest_cmake-0.11.0}/cmake/FindPytest.cmake +41 -30
- pytest_cmake-0.11.0/cmake/PytestAddTests.cmake +148 -0
- {pytest_cmake-0.5.1 → pytest_cmake-0.11.0}/pyproject.toml +8 -2
- {pytest_cmake-0.5.1 → pytest_cmake-0.11.0}/setup.py +1 -1
- pytest_cmake-0.5.1/cmake/PytestAddTests.cmake +0 -129
- {pytest_cmake-0.5.1 → pytest_cmake-0.11.0}/.gitignore +0 -0
- {pytest_cmake-0.5.1 → pytest_cmake-0.11.0}/LICENSE +0 -0
- {pytest_cmake-0.5.1 → pytest_cmake-0.11.0}/build_backend.py +0 -0
- {pytest_cmake-0.5.1 → pytest_cmake-0.11.0}/build_config.py +0 -0
@@ -1,7 +1,11 @@
|
|
1
1
|
Metadata-Version: 2.3
|
2
2
|
Name: pytest-cmake
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.11.0
|
4
4
|
Summary: Provide CMake module for Pytest
|
5
|
+
Project-URL: Documentation, https://python-cmake.github.io/pytest-cmake
|
6
|
+
Project-URL: Repository, https://github.com/python-cmake/pytest-cmake
|
7
|
+
Project-URL: Issues, https://github.com/python-cmake/pytest-cmake/issues
|
8
|
+
Project-URL: Changelog, https://python-cmake.github.io/pytest-cmake/release/release_notes.html
|
5
9
|
Author-email: Jeremy Retailleau <jeremy.retailleau@gmail.com>
|
6
10
|
License: MIT License
|
7
11
|
|
@@ -45,9 +49,8 @@ Description-Content-Type: text/markdown
|
|
45
49
|
# Pytest CMake
|
46
50
|
|
47
51
|
[](https://pypi.python.org/pypi/pytest-cmake)
|
48
|
-
[](https://github.com/buddly27/pytest-cmake/actions/workflows/test.yml)
|
52
|
+
[](https://cmake.org)
|
53
|
+
[](https://github.com/python-cmake/pytest-cmake/actions/workflows/test.yml)
|
51
54
|
[](https://opensource.org/licenses/MIT)
|
52
55
|
|
53
56
|
This project provides convenient ways to use [Pytest](https://docs.pytest.org/)
|
@@ -57,12 +60,12 @@ versions on Linux, macOS or Windows using the
|
|
57
60
|
function:
|
58
61
|
|
59
62
|
```cmake
|
60
|
-
find_package(Pytest
|
63
|
+
find_package(Pytest 8.2.1 REQUIRED)
|
61
64
|
```
|
62
65
|
|
63
66
|
A ``pytest_discover_tests`` function is provided to simplify automatic
|
64
67
|
testing for C++ projects with Python bindings. It can create CTest tests
|
65
|
-
for each Python test collected within a
|
68
|
+
for each Python test collected within a controlled environment:
|
66
69
|
|
67
70
|
```cmake
|
68
71
|
pytest_discover_tests(
|
@@ -92,4 +95,4 @@ Running the tests will display the status for each test collected as follows:
|
|
92
95
|
## Documentation
|
93
96
|
|
94
97
|
Full documentation, including installation and setup guides, can be found at
|
95
|
-
https://
|
98
|
+
https://python-cmake.github.io/pytest-cmake/
|
@@ -1,9 +1,8 @@
|
|
1
1
|
# Pytest CMake
|
2
2
|
|
3
3
|
[](https://pypi.python.org/pypi/pytest-cmake)
|
4
|
-
[](https://github.com/buddly27/pytest-cmake/actions/workflows/test.yml)
|
4
|
+
[](https://cmake.org)
|
5
|
+
[](https://github.com/python-cmake/pytest-cmake/actions/workflows/test.yml)
|
7
6
|
[](https://opensource.org/licenses/MIT)
|
8
7
|
|
9
8
|
This project provides convenient ways to use [Pytest](https://docs.pytest.org/)
|
@@ -13,12 +12,12 @@ versions on Linux, macOS or Windows using the
|
|
13
12
|
function:
|
14
13
|
|
15
14
|
```cmake
|
16
|
-
find_package(Pytest
|
15
|
+
find_package(Pytest 8.2.1 REQUIRED)
|
17
16
|
```
|
18
17
|
|
19
18
|
A ``pytest_discover_tests`` function is provided to simplify automatic
|
20
19
|
testing for C++ projects with Python bindings. It can create CTest tests
|
21
|
-
for each Python test collected within a
|
20
|
+
for each Python test collected within a controlled environment:
|
22
21
|
|
23
22
|
```cmake
|
24
23
|
pytest_discover_tests(
|
@@ -48,4 +47,4 @@ Running the tests will display the status for each test collected as follows:
|
|
48
47
|
## Documentation
|
49
48
|
|
50
49
|
Full documentation, including installation and setup guides, can be found at
|
51
|
-
https://
|
50
|
+
https://python-cmake.github.io/pytest-cmake/
|
@@ -3,9 +3,9 @@
|
|
3
3
|
# This module defines the following imported targets:
|
4
4
|
# Pytest::Pytest
|
5
5
|
#
|
6
|
-
# It also exposes the 'pytest_discover_tests' function which adds
|
7
|
-
# for each
|
8
|
-
# can be used to run all discovered tests
|
6
|
+
# It also exposes the 'pytest_discover_tests' function, which adds CTest
|
7
|
+
# test for each Pytest test. The "BUNDLE_PYTHON_TESTS" environment variable
|
8
|
+
# can be used to run all discovered tests together.
|
9
9
|
#
|
10
10
|
# Usage:
|
11
11
|
# find_package(Pytest)
|
@@ -17,7 +17,7 @@
|
|
17
17
|
# prepend a custom search path.
|
18
18
|
# (https://cmake.org/cmake/help/latest/policy/CMP0074.html)
|
19
19
|
|
20
|
-
cmake_minimum_required(VERSION 3.20...3.
|
20
|
+
cmake_minimum_required(VERSION 3.20...3.30)
|
21
21
|
|
22
22
|
include(FindPackageHandleStandardArgs)
|
23
23
|
|
@@ -53,59 +53,59 @@ if (Pytest_FOUND AND NOT TARGET Pytest::Pytest)
|
|
53
53
|
PROPERTIES
|
54
54
|
IMPORTED_LOCATION "${PYTEST_EXECUTABLE}")
|
55
55
|
|
56
|
+
# Function to discover pytest tests and add them to CTest.
|
56
57
|
function(pytest_discover_tests NAME)
|
57
58
|
cmake_parse_arguments(
|
58
|
-
PARSE_ARGV 1 "" ""
|
59
|
-
"WORKING_DIRECTORY;TRIM_FROM_NAME;
|
60
|
-
"LIBRARY_PATH_PREPEND;PYTHON_PATH_PREPEND;ENVIRONMENT;DEPENDS"
|
59
|
+
PARSE_ARGV 1 "" "STRIP_PARAM_BRACKETS;INCLUDE_FILE_PATH;BUNDLE_TESTS"
|
60
|
+
"WORKING_DIRECTORY;TRIM_FROM_NAME;TRIM_FROM_FULL_NAME"
|
61
|
+
"LIBRARY_PATH_PREPEND;PYTHON_PATH_PREPEND;ENVIRONMENT;PROPERTIES;DEPENDS"
|
61
62
|
)
|
62
63
|
|
63
|
-
# Set library path
|
64
|
+
# Set platform-specific library path environment variable.
|
64
65
|
if (CMAKE_SYSTEM_NAME STREQUAL Windows)
|
65
|
-
set(
|
66
|
-
set(_env_sep "\\\;")
|
66
|
+
set(LIBRARY_ENV_NAME PATH)
|
67
67
|
elseif(CMAKE_SYSTEM_NAME STREQUAL Darwin)
|
68
|
-
set(
|
69
|
-
set(_env_sep ":")
|
68
|
+
set(LIBRARY_ENV_NAME DYLD_LIBRARY_PATH)
|
70
69
|
else()
|
71
|
-
set(
|
72
|
-
set(_env_sep ":")
|
70
|
+
set(LIBRARY_ENV_NAME LD_LIBRARY_PATH)
|
73
71
|
endif()
|
74
72
|
|
75
|
-
# Convert
|
76
|
-
cmake_path(CONVERT "$ENV{${
|
77
|
-
cmake_path(CONVERT "$ENV{PYTHONPATH}" TO_CMAKE_PATH_LIST
|
73
|
+
# Convert paths to CMake-friendly format.
|
74
|
+
cmake_path(CONVERT "$ENV{${LIBRARY_ENV_NAME}}" TO_CMAKE_PATH_LIST LIBRARY_PATH)
|
75
|
+
cmake_path(CONVERT "$ENV{PYTHONPATH}" TO_CMAKE_PATH_LIST PYTHON_PATH)
|
78
76
|
|
79
|
-
# Prepend
|
77
|
+
# Prepend specified paths to the library and Python paths.
|
80
78
|
if (_LIBRARY_PATH_PREPEND)
|
81
79
|
list(REVERSE _LIBRARY_PATH_PREPEND)
|
82
80
|
foreach (_path ${_LIBRARY_PATH_PREPEND})
|
83
|
-
set(
|
81
|
+
set(LIBRARY_PATH "${_path}" "${LIBRARY_PATH}")
|
84
82
|
endforeach()
|
85
83
|
endif()
|
86
84
|
|
87
85
|
if (_PYTHON_PATH_PREPEND)
|
88
86
|
list(REVERSE _PYTHON_PATH_PREPEND)
|
89
87
|
foreach (_path ${_PYTHON_PATH_PREPEND})
|
90
|
-
set(
|
88
|
+
set(PYTHON_PATH "${_path}" "${PYTHON_PATH}")
|
91
89
|
endforeach()
|
92
90
|
endif()
|
93
91
|
|
94
|
-
#
|
95
|
-
list(JOIN libpath "${_env_sep}" libpath)
|
96
|
-
list(JOIN pythonpath "${_env_sep}" pythonpath)
|
97
|
-
|
92
|
+
# Set default working directory if none is specified.
|
98
93
|
if (NOT _WORKING_DIRECTORY)
|
99
94
|
set(_WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
|
100
95
|
endif()
|
101
96
|
|
97
|
+
get_filename_component(_WORKING_DIRECTORY "${_WORKING_DIRECTORY}" REALPATH)
|
98
|
+
|
102
99
|
# Override option by environment variable if available.
|
103
100
|
if (DEFINED ENV{BUNDLE_PYTHON_TESTS})
|
104
101
|
set(_BUNDLE_TESTS $ENV{BUNDLE_PYTHON_TESTS})
|
105
102
|
endif()
|
106
103
|
|
104
|
+
# Define file paths for generated CMake include files.
|
105
|
+
set(_include_file "${CMAKE_CURRENT_BINARY_DIR}/${NAME}_include.cmake")
|
107
106
|
set(_tests_file "${CMAKE_CURRENT_BINARY_DIR}/${NAME}_tests.cmake")
|
108
107
|
|
108
|
+
# Create a custom target to run the tests.
|
109
109
|
add_custom_target(
|
110
110
|
${NAME} ALL VERBATIM
|
111
111
|
BYPRODUCTS "${_tests_file}"
|
@@ -114,19 +114,30 @@ if (Pytest_FOUND AND NOT TARGET Pytest::Pytest)
|
|
114
114
|
-D "PYTEST_EXECUTABLE=${PYTEST_EXECUTABLE}"
|
115
115
|
-D "TEST_GROUP_NAME=${NAME}"
|
116
116
|
-D "BUNDLE_TESTS=${_BUNDLE_TESTS}"
|
117
|
-
-D "
|
118
|
-
-D "LIBRARY_PATH=${
|
119
|
-
-D "PYTHON_PATH=${
|
117
|
+
-D "LIBRARY_ENV_NAME=${LIBRARY_ENV_NAME}"
|
118
|
+
-D "LIBRARY_PATH=${LIBRARY_PATH}"
|
119
|
+
-D "PYTHON_PATH=${PYTHON_PATH}"
|
120
120
|
-D "TRIM_FROM_NAME=${_TRIM_FROM_NAME}"
|
121
|
+
-D "TRIM_FROM_FULL_NAME=${_TRIM_FROM_FULL_NAME}"
|
122
|
+
-D "STRIP_PARAM_BRACKETS=${_STRIP_PARAM_BRACKETS}"
|
123
|
+
-D "INCLUDE_FILE_PATH=${_INCLUDE_FILE_PATH}"
|
121
124
|
-D "WORKING_DIRECTORY=${_WORKING_DIRECTORY}"
|
122
125
|
-D "ENVIRONMENT=${_ENVIRONMENT}"
|
123
|
-
-D "
|
126
|
+
-D "TEST_PROPERTIES=${_PROPERTIES}"
|
124
127
|
-D "CTEST_FILE=${_tests_file}"
|
125
128
|
-P "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/PytestAddTests.cmake")
|
126
129
|
|
127
|
-
|
130
|
+
file(WRITE "${_include_file}"
|
131
|
+
"if(EXISTS \"${_tests_file}\")\n"
|
132
|
+
" include(\"${_tests_file}\")\n"
|
133
|
+
"else()\n"
|
134
|
+
" add_test(${NAME}_NOT_BUILT ${NAME}_NOT_BUILT)\n"
|
135
|
+
"endif()\n"
|
136
|
+
)
|
137
|
+
|
138
|
+
# Register the include file to be processed for tests.
|
128
139
|
set_property(DIRECTORY
|
129
|
-
APPEND PROPERTY TEST_INCLUDE_FILES "${
|
140
|
+
APPEND PROPERTY TEST_INCLUDE_FILES "${_include_file}")
|
130
141
|
|
131
142
|
endfunction()
|
132
143
|
|
@@ -0,0 +1,148 @@
|
|
1
|
+
# Wrapper used to create individual CTest tests from Pytest tests.
|
2
|
+
cmake_minimum_required(VERSION 3.20...3.30)
|
3
|
+
|
4
|
+
if(CMAKE_SCRIPT_MODE_FILE)
|
5
|
+
|
6
|
+
# Initialize content for the CMake test file.
|
7
|
+
set(_content "")
|
8
|
+
|
9
|
+
# Convert library and Python paths to native format.
|
10
|
+
cmake_path(CONVERT "${LIBRARY_PATH}" TO_NATIVE_PATH_LIST LIBRARY_PATH)
|
11
|
+
cmake_path(CONVERT "${PYTHON_PATH}" TO_NATIVE_PATH_LIST PYTHON_PATH)
|
12
|
+
|
13
|
+
# Serialize path values separated by semicolons (required on Windows).
|
14
|
+
string(REPLACE [[;]] [[\\;]] LIBRARY_PATH "${LIBRARY_PATH}")
|
15
|
+
string(REPLACE [[;]] [[\\;]] PYTHON_PATH "${PYTHON_PATH}")
|
16
|
+
|
17
|
+
# Set up the encoded environment with required paths.
|
18
|
+
set(ENCODED_ENVIRONMENT
|
19
|
+
"${LIBRARY_ENV_NAME}=${LIBRARY_PATH}"
|
20
|
+
"PYTHONPATH=${PYTHON_PATH}"
|
21
|
+
)
|
22
|
+
|
23
|
+
# Serialize additional environment variables if any are provided.
|
24
|
+
foreach(env ${ENVIRONMENT})
|
25
|
+
string(REPLACE [[;]] [[\\;]] env "${env}")
|
26
|
+
list(APPEND ENCODED_ENVIRONMENT "${env}")
|
27
|
+
endforeach()
|
28
|
+
|
29
|
+
# Macro to create individual tests with optional test properties.
|
30
|
+
macro(create_test NAME IDENTIFIER)
|
31
|
+
string(APPEND _content
|
32
|
+
"add_test(\"${NAME}\" \"${PYTEST_EXECUTABLE}\" \"${IDENTIFIER}\")\n"
|
33
|
+
)
|
34
|
+
|
35
|
+
# Prepare the properties for the test, including the environment settings.
|
36
|
+
set(args "PROPERTIES ENVIRONMENT [==[${ENCODED_ENVIRONMENT}]==]")
|
37
|
+
|
38
|
+
# Append any additional properties, escaping complex characters if necessary.
|
39
|
+
foreach(property ${TEST_PROPERTIES})
|
40
|
+
if(property MATCHES "[^-./:a-zA-Z0-9_]")
|
41
|
+
string(APPEND args " [==[${property}]==]")
|
42
|
+
else()
|
43
|
+
string(APPEND args " ${property}")
|
44
|
+
endif()
|
45
|
+
endforeach()
|
46
|
+
|
47
|
+
# Append the test properties to the content.
|
48
|
+
string(APPEND _content "set_tests_properties(\"${NAME}\" ${args})\n")
|
49
|
+
endmacro()
|
50
|
+
|
51
|
+
# If tests are bundled together, create a single test group.
|
52
|
+
if (BUNDLE_TESTS)
|
53
|
+
create_test("${TEST_GROUP_NAME}" "${WORKING_DIRECTORY}")
|
54
|
+
|
55
|
+
else()
|
56
|
+
# Set environment variables for collecting tests.
|
57
|
+
set(ENV{${LIBRARY_ENV_NAME}} "${LIBRARY_PATH}")
|
58
|
+
set(ENV{PYTHONPATH} "${PYTHON_PATH}")
|
59
|
+
set(ENV{PYTHONWARNINGS} "ignore")
|
60
|
+
|
61
|
+
# Collect tests.
|
62
|
+
execute_process(
|
63
|
+
COMMAND "${PYTEST_EXECUTABLE}"
|
64
|
+
--collect-only -q
|
65
|
+
--rootdir=${WORKING_DIRECTORY} .
|
66
|
+
OUTPUT_VARIABLE _output_lines
|
67
|
+
ERROR_VARIABLE _output_lines
|
68
|
+
OUTPUT_STRIP_TRAILING_WHITESPACE
|
69
|
+
WORKING_DIRECTORY ${WORKING_DIRECTORY}
|
70
|
+
)
|
71
|
+
|
72
|
+
# Check for errors during test collection.
|
73
|
+
string(REGEX MATCH "=+ ERRORS =+(.*)" _error "${_output_lines}")
|
74
|
+
|
75
|
+
if (_error)
|
76
|
+
message(${_error})
|
77
|
+
message(FATAL_ERROR "An error occurred during the collection of Python tests.")
|
78
|
+
endif()
|
79
|
+
|
80
|
+
# Convert the collected output into a list of lines.
|
81
|
+
string(REPLACE [[;]] [[\;]] _output_lines "${_output_lines}")
|
82
|
+
string(REPLACE "\n" ";" _output_lines "${_output_lines}")
|
83
|
+
|
84
|
+
# Regex pattern to identify pytest test identifiers.
|
85
|
+
set(test_pattern "([^:]+)\.py(::([^:]+))?::([^:]+)")
|
86
|
+
|
87
|
+
# Iterate through each line to identify and process tests.
|
88
|
+
foreach(line ${_output_lines})
|
89
|
+
string(REGEX MATCHALL ${test_pattern} matching "${line}")
|
90
|
+
|
91
|
+
# Skip lines that are not identified as tests.
|
92
|
+
if (NOT matching)
|
93
|
+
continue()
|
94
|
+
endif()
|
95
|
+
|
96
|
+
# Extract file, class, and function names from the test pattern.
|
97
|
+
set(_file ${CMAKE_MATCH_1})
|
98
|
+
set(_class ${CMAKE_MATCH_3})
|
99
|
+
set(_func ${CMAKE_MATCH_4})
|
100
|
+
|
101
|
+
# Optionally trim parts of the class or function name.
|
102
|
+
if (TRIM_FROM_NAME)
|
103
|
+
string(REGEX REPLACE "${TRIM_FROM_NAME}" "" _class "${_class}")
|
104
|
+
string(REGEX REPLACE "${TRIM_FROM_NAME}" "" _func "${_func}")
|
105
|
+
endif()
|
106
|
+
|
107
|
+
# Form the test name using class and function.
|
108
|
+
if (_class)
|
109
|
+
set(test_name "${_class}.${_func}")
|
110
|
+
else()
|
111
|
+
set(test_name "${_func}")
|
112
|
+
endif()
|
113
|
+
|
114
|
+
# Optionally strip parameter brackets from the test name.
|
115
|
+
if (STRIP_PARAM_BRACKETS)
|
116
|
+
string(REGEX REPLACE "\\[(.+)\\]$" ".\\1" test_name "${test_name}")
|
117
|
+
endif()
|
118
|
+
|
119
|
+
# Optionally include the file path in the test name.
|
120
|
+
if (INCLUDE_FILE_PATH)
|
121
|
+
cmake_path(CONVERT "${_file}" TO_CMAKE_PATH_LIST _file)
|
122
|
+
string(REGEX REPLACE "/" "." _file "${_file}")
|
123
|
+
set(test_name "${_file}.${test_name}")
|
124
|
+
endif()
|
125
|
+
|
126
|
+
# Optionally trim parts of the full test name.
|
127
|
+
if (TRIM_FROM_FULL_NAME)
|
128
|
+
string(REGEX REPLACE "${TRIM_FROM_FULL_NAME}" "" test_name "${test_name}")
|
129
|
+
endif()
|
130
|
+
|
131
|
+
# Prefix the test name with the test group name.
|
132
|
+
set(test_name "${TEST_GROUP_NAME}.${test_name}")
|
133
|
+
set(test_case "${WORKING_DIRECTORY}/${line}")
|
134
|
+
|
135
|
+
# Create the test for CTest.
|
136
|
+
create_test("${test_name}" "${test_case}")
|
137
|
+
endforeach()
|
138
|
+
|
139
|
+
# Warn if no tests were discovered.
|
140
|
+
if(NOT _content)
|
141
|
+
message(WARNING "No Python tests have been discovered.")
|
142
|
+
endif()
|
143
|
+
endif()
|
144
|
+
|
145
|
+
# Write the generated test content to the specified CTest file.
|
146
|
+
file(WRITE ${CTEST_FILE} ${_content})
|
147
|
+
|
148
|
+
endif()
|
@@ -2,14 +2,14 @@
|
|
2
2
|
requires = [
|
3
3
|
"hatchling >= 1.4; python_version >= '3'",
|
4
4
|
"setuptools >= 44; python_version < '3'",
|
5
|
-
"cmake >= 3.20, < 3.
|
5
|
+
"cmake >= 3.20, < 3.31"
|
6
6
|
]
|
7
7
|
build-backend = "build_backend"
|
8
8
|
backend-path = ["."]
|
9
9
|
|
10
10
|
[project]
|
11
11
|
name = "pytest-cmake"
|
12
|
-
version = "0.
|
12
|
+
version = "0.11.0"
|
13
13
|
description = "Provide CMake module for Pytest"
|
14
14
|
readme = "README.md"
|
15
15
|
requires-python = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*, <4"
|
@@ -36,6 +36,12 @@ classifiers = [
|
|
36
36
|
"Programming Language :: Python :: 3.12",
|
37
37
|
]
|
38
38
|
|
39
|
+
[project.urls]
|
40
|
+
Documentation = "https://python-cmake.github.io/pytest-cmake"
|
41
|
+
Repository = "https://github.com/python-cmake/pytest-cmake"
|
42
|
+
Issues = "https://github.com/python-cmake/pytest-cmake/issues"
|
43
|
+
Changelog = "https://python-cmake.github.io/pytest-cmake/release/release_notes.html"
|
44
|
+
|
39
45
|
[tool.hatch.build.hooks.custom]
|
40
46
|
require-runtime-dependencies = true
|
41
47
|
path = "build_config.py"
|
@@ -1,129 +0,0 @@
|
|
1
|
-
# Wrapper used to create individual CTest tests from Pytest tests.
|
2
|
-
cmake_minimum_required(VERSION 3.20...3.29)
|
3
|
-
|
4
|
-
if(CMAKE_SCRIPT_MODE_FILE)
|
5
|
-
|
6
|
-
# Set Cmake test file to execute each test.
|
7
|
-
set(_content "")
|
8
|
-
|
9
|
-
# Ensure that list environment variables are
|
10
|
-
# represented as a string on Windows.
|
11
|
-
string(REPLACE [[;]] [[\;]] LIBRARY_PATH "${LIBRARY_PATH}")
|
12
|
-
string(REPLACE [[;]] [[\;]] PYTHON_PATH "${PYTHON_PATH}")
|
13
|
-
|
14
|
-
if (BUNDLE_TESTS)
|
15
|
-
string(APPEND _content
|
16
|
-
"add_test(\n"
|
17
|
-
" \"${TEST_GROUP_NAME}\"\n"
|
18
|
-
" ${PYTEST_EXECUTABLE} \"${WORKING_DIRECTORY}\"\n"
|
19
|
-
")\n"
|
20
|
-
"set_tests_properties(\n"
|
21
|
-
" \"${TEST_GROUP_NAME}\" PROPERTIES\n"
|
22
|
-
" ENVIRONMENT \"${LIB_ENV_PATH}=${LIBRARY_PATH}\"\n"
|
23
|
-
")\n"
|
24
|
-
"set_tests_properties(\n"
|
25
|
-
" \"${TEST_GROUP_NAME}\"\n"
|
26
|
-
" APPEND PROPERTIES\n"
|
27
|
-
" ENVIRONMENT \"PYTHONPATH=${PYTHON_PATH}\"\n"
|
28
|
-
")\n"
|
29
|
-
)
|
30
|
-
|
31
|
-
foreach(env ${ENVIRONMENT})
|
32
|
-
string(APPEND _content
|
33
|
-
"set_tests_properties(\n"
|
34
|
-
" \"${TEST_GROUP_NAME}\"\n"
|
35
|
-
" APPEND PROPERTIES\n"
|
36
|
-
" ENVIRONMENT ${env}\n"
|
37
|
-
")\n"
|
38
|
-
)
|
39
|
-
endforeach()
|
40
|
-
|
41
|
-
else()
|
42
|
-
# Set environment for collecting tests.
|
43
|
-
set(ENV{${LIB_ENV_PATH}} "${LIBRARY_PATH}")
|
44
|
-
set(ENV{PYTHONPATH} "${PYTHON_PATH}")
|
45
|
-
set(ENV{PYTHONWARNINGS} "ignore")
|
46
|
-
|
47
|
-
execute_process(
|
48
|
-
COMMAND "${PYTEST_EXECUTABLE}"
|
49
|
-
--collect-only -q
|
50
|
-
--rootdir=${WORKING_DIRECTORY} .
|
51
|
-
OUTPUT_VARIABLE _output_lines
|
52
|
-
ERROR_VARIABLE _output_lines
|
53
|
-
OUTPUT_STRIP_TRAILING_WHITESPACE
|
54
|
-
WORKING_DIRECTORY ${WORKING_DIRECTORY}
|
55
|
-
)
|
56
|
-
|
57
|
-
string(REGEX MATCH "=+ ERRORS =+(.*)" _error ${_output_lines})
|
58
|
-
|
59
|
-
if (_error)
|
60
|
-
message(${_error})
|
61
|
-
message(FATAL_ERROR "An error occurred during the collection of Python tests.")
|
62
|
-
endif()
|
63
|
-
|
64
|
-
# Convert output into list.
|
65
|
-
string(REPLACE [[;]] [[\;]] _output_lines "${_output_lines}")
|
66
|
-
string(REPLACE "\n" ";" _output_lines "${_output_lines}")
|
67
|
-
|
68
|
-
set(test_pattern "([^:]+)(::([^:]+))?::([^:]+)")
|
69
|
-
|
70
|
-
foreach (line ${_output_lines})
|
71
|
-
string(REGEX MATCHALL ${test_pattern} matching "${line}")
|
72
|
-
|
73
|
-
# Ignore lines not identified as a test.
|
74
|
-
if (NOT matching)
|
75
|
-
continue()
|
76
|
-
endif()
|
77
|
-
|
78
|
-
set(_class ${CMAKE_MATCH_3})
|
79
|
-
set(_func ${CMAKE_MATCH_4})
|
80
|
-
|
81
|
-
if (_class)
|
82
|
-
set(test_name "${_class}.${_func}")
|
83
|
-
else()
|
84
|
-
set(test_name "${_func}")
|
85
|
-
endif()
|
86
|
-
|
87
|
-
if (TRIM_FROM_NAME)
|
88
|
-
string(REGEX REPLACE
|
89
|
-
"${TRIM_FROM_NAME}" "" test_name "${test_name}")
|
90
|
-
endif()
|
91
|
-
|
92
|
-
set(test_name "${TEST_GROUP_NAME}.${test_name}")
|
93
|
-
set(test_case "${WORKING_DIRECTORY}/${line}")
|
94
|
-
|
95
|
-
string(APPEND _content
|
96
|
-
"add_test(\n"
|
97
|
-
" \"${test_name}\"\n"
|
98
|
-
" ${PYTEST_EXECUTABLE} \"${test_case}\"\n"
|
99
|
-
")\n"
|
100
|
-
"set_tests_properties(\n"
|
101
|
-
" \"${test_name}\" PROPERTIES\n"
|
102
|
-
" ENVIRONMENT \"${LIB_ENV_PATH}=${LIBRARY_PATH}\"\n"
|
103
|
-
")\n"
|
104
|
-
"set_tests_properties(\n"
|
105
|
-
" \"${test_name}\"\n"
|
106
|
-
" APPEND PROPERTIES\n"
|
107
|
-
" ENVIRONMENT \"PYTHONPATH=${PYTHON_PATH}\"\n"
|
108
|
-
")\n"
|
109
|
-
)
|
110
|
-
|
111
|
-
foreach(env ${ENVIRONMENT})
|
112
|
-
string(APPEND _content
|
113
|
-
"set_tests_properties(\n"
|
114
|
-
" \"${test_name}\"\n"
|
115
|
-
" APPEND PROPERTIES\n"
|
116
|
-
" ENVIRONMENT ${env}\n"
|
117
|
-
")\n"
|
118
|
-
)
|
119
|
-
endforeach()
|
120
|
-
|
121
|
-
endforeach()
|
122
|
-
|
123
|
-
if(NOT _content)
|
124
|
-
message(WARNING "No Python tests have been discovered.")
|
125
|
-
endif()
|
126
|
-
endif()
|
127
|
-
|
128
|
-
file(WRITE ${CTEST_FILE} ${_content})
|
129
|
-
endif()
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|