pytest-cmake 0.4.1__tar.gz → 0.8.4__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.
@@ -1,7 +1,11 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: pytest-cmake
3
- Version: 0.4.1
3
+ Version: 0.8.4
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
 
@@ -35,6 +39,8 @@ Classifier: Programming Language :: Python :: 3.7
35
39
  Classifier: Programming Language :: Python :: 3.8
36
40
  Classifier: Programming Language :: Python :: 3.9
37
41
  Classifier: Programming Language :: Python :: 3.10
42
+ Classifier: Programming Language :: Python :: 3.11
43
+ Classifier: Programming Language :: Python :: 3.12
38
44
  Classifier: Topic :: Software Development :: Build Tools
39
45
  Requires-Python: !=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,<4,>=2.7
40
46
  Requires-Dist: pytest<9,>=4
@@ -43,9 +49,8 @@ Description-Content-Type: text/markdown
43
49
  # Pytest CMake
44
50
 
45
51
  [![PyPi version](https://img.shields.io/pypi/v/pytest-cmake.svg?logo=pypi&label=PyPI&logoColor=gold)](https://pypi.python.org/pypi/pytest-cmake)
46
- [![CMake](https://img.shields.io/badge/CMake-3.20...3.29-blue.svg?logo=CMake&logoColor=blue)](https://cmake.org)
47
- [![Documentation](https://readthedocs.org/projects/pytest-cmake/badge/?version=stable)](https://pytest-cmake.readthedocs.io/en/stable/)
48
- [![Test](https://github.com/buddly27/pytest-cmake/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/buddly27/pytest-cmake/actions/workflows/test.yml)
52
+ [![CMake](https://img.shields.io/badge/CMake-3.20...3.30-blue.svg?logo=CMake&logoColor=blue)](https://cmake.org)
53
+ [![Test](https://github.com/python-cmake/pytest-cmake/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/python-cmake/pytest-cmake/actions/workflows/test.yml)
49
54
  [![License](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
50
55
 
51
56
  This project provides convenient ways to use [Pytest](https://docs.pytest.org/)
@@ -55,12 +60,12 @@ versions on Linux, macOS or Windows using the
55
60
  function:
56
61
 
57
62
  ```cmake
58
- find_package(Pytest 4.6.11 REQUIRED)
63
+ find_package(Pytest 8.2.1 REQUIRED)
59
64
  ```
60
65
 
61
66
  A ``pytest_discover_tests`` function is provided to simplify automatic
62
67
  testing for C++ projects with Python bindings. It can create CTest tests
63
- for each Python test collected within a correct environment:
68
+ for each Python test collected within a controlled environment:
64
69
 
65
70
  ```cmake
66
71
  pytest_discover_tests(
@@ -90,4 +95,4 @@ Running the tests will display the status for each test collected as follows:
90
95
  ## Documentation
91
96
 
92
97
  Full documentation, including installation and setup guides, can be found at
93
- https://pytest-cmake.readthedocs.io/en/stable/
98
+ https://python-cmake.github.io/pytest-cmake/
@@ -1,9 +1,8 @@
1
1
  # Pytest CMake
2
2
 
3
3
  [![PyPi version](https://img.shields.io/pypi/v/pytest-cmake.svg?logo=pypi&label=PyPI&logoColor=gold)](https://pypi.python.org/pypi/pytest-cmake)
4
- [![CMake](https://img.shields.io/badge/CMake-3.20...3.29-blue.svg?logo=CMake&logoColor=blue)](https://cmake.org)
5
- [![Documentation](https://readthedocs.org/projects/pytest-cmake/badge/?version=stable)](https://pytest-cmake.readthedocs.io/en/stable/)
6
- [![Test](https://github.com/buddly27/pytest-cmake/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/buddly27/pytest-cmake/actions/workflows/test.yml)
4
+ [![CMake](https://img.shields.io/badge/CMake-3.20...3.30-blue.svg?logo=CMake&logoColor=blue)](https://cmake.org)
5
+ [![Test](https://github.com/python-cmake/pytest-cmake/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/python-cmake/pytest-cmake/actions/workflows/test.yml)
7
6
  [![License](https://img.shields.io/badge/License-MIT-yellow.svg)](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 4.6.11 REQUIRED)
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 correct environment:
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://pytest-cmake.readthedocs.io/en/stable/
50
+ https://python-cmake.github.io/pytest-cmake/
@@ -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.29)
20
+ cmake_minimum_required(VERSION 3.20...3.30)
21
21
 
22
22
  include(FindPackageHandleStandardArgs)
23
23
 
@@ -60,50 +60,55 @@ if (Pytest_FOUND AND NOT TARGET Pytest::Pytest)
60
60
  "LIBRARY_PATH_PREPEND;PYTHON_PATH_PREPEND;ENVIRONMENT;DEPENDS"
61
61
  )
62
62
 
63
- # Set library path depending on the platform.
63
+ # Identify library path environment name depending on the platform.
64
64
  if (CMAKE_SYSTEM_NAME STREQUAL Windows)
65
- set(LIB_ENV_PATH PATH)
66
- set(_env_sep "\\\;")
65
+ set(LIBRARY_ENV_NAME PATH)
67
66
  elseif(CMAKE_SYSTEM_NAME STREQUAL Darwin)
68
- set(LIB_ENV_PATH DYLD_LIBRARY_PATH)
69
- set(_env_sep ":")
67
+ set(LIBRARY_ENV_NAME DYLD_LIBRARY_PATH)
70
68
  else()
71
- set(LIB_ENV_PATH LD_LIBRARY_PATH)
72
- set(_env_sep ":")
69
+ set(LIBRARY_ENV_NAME LD_LIBRARY_PATH)
73
70
  endif()
74
71
 
75
- # Convert all paths into cmake paths.
76
- cmake_path(CONVERT "$ENV{${LIB_ENV_PATH}}" TO_CMAKE_PATH_LIST libpath)
77
- cmake_path(CONVERT "$ENV{PYTHONPATH}" TO_CMAKE_PATH_LIST pythonpath)
72
+ # Sanitize all paths for CMake.
73
+ cmake_path(CONVERT "$ENV{${LIBRARY_ENV_NAME}}" TO_CMAKE_PATH_LIST LIBRARY_PATH)
74
+ cmake_path(CONVERT "$ENV{PYTHONPATH}" TO_CMAKE_PATH_LIST PYTHON_PATH)
78
75
 
79
- # Prepend input path to environment variables
76
+ # Prepend input path to environment variables.
80
77
  if (_LIBRARY_PATH_PREPEND)
81
78
  list(REVERSE _LIBRARY_PATH_PREPEND)
82
79
  foreach (_path ${_LIBRARY_PATH_PREPEND})
83
- set(libpath "${_path}" "${libpath}")
80
+ set(LIBRARY_PATH "${_path}" "${LIBRARY_PATH}")
84
81
  endforeach()
85
82
  endif()
86
83
 
87
84
  if (_PYTHON_PATH_PREPEND)
88
85
  list(REVERSE _PYTHON_PATH_PREPEND)
89
86
  foreach (_path ${_PYTHON_PATH_PREPEND})
90
- set(pythonpath "${_path}" "${pythonpath}")
87
+ set(PYTHON_PATH "${_path}" "${PYTHON_PATH}")
91
88
  endforeach()
92
89
  endif()
93
90
 
94
- # Convert list into string.
95
- list(JOIN libpath "${_env_sep}" libpath)
96
- list(JOIN pythonpath "${_env_sep}" pythonpath)
97
-
91
+ # Default working directory to current build path if none is provided.
98
92
  if (NOT _WORKING_DIRECTORY)
99
93
  set(_WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
100
94
  endif()
101
95
 
96
+ get_filename_component(_WORKING_DIRECTORY "${_WORKING_DIRECTORY}" REALPATH)
97
+
102
98
  # Override option by environment variable if available.
103
99
  if (DEFINED ENV{BUNDLE_PYTHON_TESTS})
104
100
  set(_BUNDLE_TESTS $ENV{BUNDLE_PYTHON_TESTS})
105
101
  endif()
106
102
 
103
+ # Serialize environment if necessary.
104
+ set(ENCODED_ENVIRONMENT "")
105
+ foreach(env ${_ENVIRONMENT})
106
+ string(REPLACE [[\]] [\\]] env ${env})
107
+ string(REPLACE [[;]] [\\;]] env ${env})
108
+ list(APPEND ENCODED_ENVIRONMENT ${env})
109
+ endforeach()
110
+
111
+ set(_include_file "${CMAKE_CURRENT_BINARY_DIR}/${NAME}_include.cmake")
107
112
  set(_tests_file "${CMAKE_CURRENT_BINARY_DIR}/${NAME}_tests.cmake")
108
113
 
109
114
  add_custom_target(
@@ -114,19 +119,27 @@ if (Pytest_FOUND AND NOT TARGET Pytest::Pytest)
114
119
  -D "PYTEST_EXECUTABLE=${PYTEST_EXECUTABLE}"
115
120
  -D "TEST_GROUP_NAME=${NAME}"
116
121
  -D "BUNDLE_TESTS=${_BUNDLE_TESTS}"
117
- -D "LIB_ENV_PATH=${LIB_ENV_PATH}"
118
- -D "LIBRARY_PATH=${libpath}"
119
- -D "PYTHON_PATH=${pythonpath}"
122
+ -D "LIBRARY_ENV_NAME=${LIBRARY_ENV_NAME}"
123
+ -D "LIBRARY_PATH=${LIBRARY_PATH}"
124
+ -D "PYTHON_PATH=${PYTHON_PATH}"
120
125
  -D "TRIM_FROM_NAME=${_TRIM_FROM_NAME}"
121
126
  -D "WORKING_DIRECTORY=${_WORKING_DIRECTORY}"
122
- -D "ENVIRONMENT=${_ENVIRONMENT}"
127
+ -D "ENVIRONMENT=${ENCODED_ENVIRONMENT}"
123
128
  -D "PROJECT_SOURCE_DIR=${PROJECT_SOURCE_DIR}"
124
129
  -D "CTEST_FILE=${_tests_file}"
125
130
  -P "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/PytestAddTests.cmake")
126
131
 
132
+ file(WRITE "${_include_file}"
133
+ "if(EXISTS \"${_tests_file}\")\n"
134
+ " include(\"${_tests_file}\")\n"
135
+ "else()\n"
136
+ " add_test(${NAME}_NOT_BUILT ${NAME}_NOT_BUILT)\n"
137
+ "endif()\n"
138
+ )
139
+
127
140
  # Add discovered tests to directory TEST_INCLUDE_FILES
128
141
  set_property(DIRECTORY
129
- APPEND PROPERTY TEST_INCLUDE_FILES "${_tests_file}")
142
+ APPEND PROPERTY TEST_INCLUDE_FILES "${_include_file}")
130
143
 
131
144
  endfunction()
132
145
 
@@ -1,25 +1,32 @@
1
1
  # Wrapper used to create individual CTest tests from Pytest tests.
2
- cmake_minimum_required(VERSION 3.20...3.29)
2
+ cmake_minimum_required(VERSION 3.20...3.30)
3
3
 
4
4
  if(CMAKE_SCRIPT_MODE_FILE)
5
5
 
6
6
  # Set Cmake test file to execute each test.
7
7
  set(_content "")
8
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}")
9
+ cmake_path(CONVERT "${LIBRARY_PATH}" TO_NATIVE_PATH_LIST LIBRARY_PATH)
10
+ cmake_path(CONVERT "${PYTHON_PATH}" TO_NATIVE_PATH_LIST PYTHON_PATH)
11
+
12
+ # Serialize path values separated by semicolons (required on Windows).
13
+ macro(encode_value VARIABLE_NAME)
14
+ string(REPLACE [[\]] [[\\]] ${VARIABLE_NAME} "${${VARIABLE_NAME}}")
15
+ string(REPLACE [[;]] [[\\;]] ${VARIABLE_NAME} "${${VARIABLE_NAME}}")
16
+ endmacro()
17
+
18
+ encode_value(LIBRARY_PATH)
19
+ encode_value(PYTHON_PATH)
13
20
 
14
21
  if (BUNDLE_TESTS)
15
22
  string(APPEND _content
16
23
  "add_test(\n"
17
24
  " \"${TEST_GROUP_NAME}\"\n"
18
- " ${PYTEST_EXECUTABLE} \"${WORKING_DIRECTORY}\"\n"
25
+ " \"${PYTEST_EXECUTABLE}\" \"${WORKING_DIRECTORY}\"\n"
19
26
  ")\n"
20
27
  "set_tests_properties(\n"
21
28
  " \"${TEST_GROUP_NAME}\" PROPERTIES\n"
22
- " ENVIRONMENT \"${LIB_ENV_PATH}=${LIBRARY_PATH}\"\n"
29
+ " ENVIRONMENT \"${LIBRARY_ENV_NAME}=${LIBRARY_PATH}\"\n"
23
30
  ")\n"
24
31
  "set_tests_properties(\n"
25
32
  " \"${TEST_GROUP_NAME}\"\n"
@@ -40,58 +47,67 @@ if(CMAKE_SCRIPT_MODE_FILE)
40
47
 
41
48
  else()
42
49
  # Set environment for collecting tests.
43
- set(ENV{${LIB_ENV_PATH}} "${LIBRARY_PATH}")
50
+ set(ENV{${LIBRARY_ENV_NAME}} "${LIBRARY_PATH}")
44
51
  set(ENV{PYTHONPATH} "${PYTHON_PATH}")
52
+ set(ENV{PYTHONWARNINGS} "ignore")
45
53
 
46
54
  execute_process(
47
- COMMAND ${PYTEST_EXECUTABLE}
55
+ COMMAND "${PYTEST_EXECUTABLE}"
48
56
  --collect-only -q
49
57
  --rootdir=${WORKING_DIRECTORY} .
50
- OUTPUT_VARIABLE _output_list
51
- ERROR_VARIABLE _output_list
58
+ OUTPUT_VARIABLE _output_lines
59
+ ERROR_VARIABLE _output_lines
52
60
  OUTPUT_STRIP_TRAILING_WHITESPACE
53
61
  WORKING_DIRECTORY ${WORKING_DIRECTORY}
54
62
  )
55
63
 
64
+ string(REGEX MATCH "=+ ERRORS =+(.*)" _error ${_output_lines})
65
+
66
+ if (_error)
67
+ message(${_error})
68
+ message(FATAL_ERROR "An error occurred during the collection of Python tests.")
69
+ endif()
70
+
56
71
  # Convert output into list.
57
- string(REPLACE [[;]] [[\;]] _output_list "${_output_list}")
58
- string(REPLACE "\n" ";" _output_list "${_output_list}")
72
+ string(REPLACE [[;]] [[\;]] _output_lines "${_output_lines}")
73
+ string(REPLACE "\n" ";" _output_lines "${_output_lines}")
59
74
 
60
75
  set(test_pattern "([^:]+)(::([^:]+))?::([^:]+)")
61
76
 
62
- foreach (test_case ${_output_list})
63
- string(REGEX MATCHALL ${test_pattern} _test_case "${test_case}")
77
+ foreach (line ${_output_lines})
78
+ string(REGEX MATCHALL ${test_pattern} matching "${line}")
64
79
 
65
80
  # Ignore lines not identified as a test.
66
- if (NOT _test_case)
81
+ if (NOT matching)
67
82
  continue()
68
83
  endif()
69
84
 
70
85
  set(_class ${CMAKE_MATCH_3})
71
86
  set(_func ${CMAKE_MATCH_4})
72
87
 
88
+ if (TRIM_FROM_NAME)
89
+ set(pattern "${TRIM_FROM_NAME}")
90
+ string(REGEX REPLACE "${pattern}" "" _class "${_class}")
91
+ string(REGEX REPLACE "${pattern}" "" _func "${_func}")
92
+ endif()
93
+
73
94
  if (_class)
74
95
  set(test_name "${_class}.${_func}")
75
96
  else()
76
97
  set(test_name "${_func}")
77
98
  endif()
78
99
 
79
- if (TRIM_FROM_NAME)
80
- string(REGEX REPLACE
81
- "${TRIM_FROM_NAME}" "" test_name "${test_name}")
82
- endif()
83
-
84
100
  set(test_name "${TEST_GROUP_NAME}.${test_name}")
85
- set(test_case "${WORKING_DIRECTORY}/${test_case}")
101
+ set(test_case "${WORKING_DIRECTORY}/${line}")
86
102
 
87
103
  string(APPEND _content
88
104
  "add_test(\n"
89
105
  " \"${test_name}\"\n"
90
- " ${PYTEST_EXECUTABLE} \"${test_case}\"\n"
106
+ " \"${PYTEST_EXECUTABLE}\" \"${test_case}\"\n"
91
107
  ")\n"
92
108
  "set_tests_properties(\n"
93
109
  " \"${test_name}\" PROPERTIES\n"
94
- " ENVIRONMENT \"${LIB_ENV_PATH}=${LIBRARY_PATH}\"\n"
110
+ " ENVIRONMENT \"${LIBRARY_ENV_NAME}=${LIBRARY_PATH}\"\n"
95
111
  ")\n"
96
112
  "set_tests_properties(\n"
97
113
  " \"${test_name}\"\n"
@@ -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.30"
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.4.1"
12
+ version = "0.8.4"
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"
@@ -32,8 +32,16 @@ classifiers = [
32
32
  "Programming Language :: Python :: 3.8",
33
33
  "Programming Language :: Python :: 3.9",
34
34
  "Programming Language :: Python :: 3.10",
35
+ "Programming Language :: Python :: 3.11",
36
+ "Programming Language :: Python :: 3.12",
35
37
  ]
36
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
+
37
45
  [tool.hatch.build.hooks.custom]
38
46
  require-runtime-dependencies = true
39
47
  path = "build_config.py"
@@ -60,7 +60,7 @@ class CreateCmakeConfig(install):
60
60
 
61
61
  setup(
62
62
  name="pytest-cmake",
63
- version="0.4.1",
63
+ version="0.8.4",
64
64
  data_files=[
65
65
  (
66
66
  "share/Pytest/cmake",
File without changes
File without changes