https://github.com/python-cmake/pytest-cmake
Pytest module for CMake
https://github.com/python-cmake/pytest-cmake
cmake development pytest python
Last synced: 5 months ago
JSON representation
Pytest module for CMake
- Host: GitHub
- URL: https://github.com/python-cmake/pytest-cmake
- Owner: python-cmake
- License: mit
- Created: 2022-11-17T04:04:43.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-08-10T18:49:39.000Z (10 months ago)
- Last Synced: 2025-08-10T19:29:25.489Z (10 months ago)
- Topics: cmake, development, pytest, python
- Language: CMake
- Homepage: https://python-cmake.github.io/pytest-cmake/
- Size: 102 KB
- Stars: 29
- Watchers: 2
- Forks: 5
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Pytest CMake
[](https://pypi.python.org/pypi/pytest-cmake)
[](https://cmake.org)
[](https://github.com/python-cmake/pytest-cmake/actions/workflows/test.yml)
[](https://opensource.org/licenses/MIT)
This project provides convenient ways to use [Pytest](https://docs.pytest.org/)
within a [CMake](https://cmake.org/) project. The package can be discovered from a specific range of
versions on Linux, macOS or Windows using the
[find_package](https://cmake.org/cmake/help/latest/command/find_package.html)
function:
```cmake
find_package(Pytest 8.2.1 REQUIRED)
```
A ``pytest_discover_tests`` function is provided to simplify automatic
testing for C++ projects with Python bindings. It can create CTest tests
for each Python test collected within a controlled environment:
```cmake
pytest_discover_tests(
PythonTest
LIBRARY_PATH_PREPEND
$
PYTHON_PATH_PREPEND
$
TRIM_FROM_NAME "^test_"
DEPENDS MyLibrary
)
```
Running the tests will display the status for each test collected as follows:
```console
Start 1: PythonTest.greet_world
1/4 Test #1: PythonTest.greet_world ........... Passed 0.47 sec
Start 2: PythonTest.greet_john
2/4 Test #2: PythonTest.greet_john ............ Passed 0.47 sec
Start 3: PythonTest.greet_julia
3/4 Test #3: PythonTest.greet_julia ........... Passed 0.47 sec
Start 4: PythonTest.greet_michael
4/4 Test #4: PythonTest.greet_michael ......... Passed 0.54 sec
```
## Documentation
Full documentation, including installation and setup guides, can be found at
https://python-cmake.github.io/pytest-cmake/