This project provides convenient ways to use Pytest within a CMake project. The package can be discovered from a specific range of versions on Linux, macOS or Windows using the find_package function:
find_package(Pytest8.2.1REQUIRED)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:
pytest_discover_tests(
PythonTestLIBRARY_PATH_PREPEND
$<TARGET_FILE_DIR:MyLibrary>
PYTHON_PATH_PREPEND
$<TARGET_FILE_DIR:MyLibrary>
TRIM_FROM_NAME"^test_"DEPENDSMyLibrary
)Running the tests will display the status for each test collected as follows:
Start 1: PythonTest.greet_world1/4 Test #1: PythonTest.greet_world ........... Passed 0.47 sec Start 2: PythonTest.greet_john2/4 Test #2: PythonTest.greet_john ............ Passed 0.47 sec Start 3: PythonTest.greet_julia3/4 Test #3: PythonTest.greet_julia ........... Passed 0.47 sec Start 4: PythonTest.greet_michael4/4 Test #4: PythonTest.greet_michael ......... Passed 0.54 secFull documentation, including installation and setup guides, can be found at https://python-cmake.github.io/pytest-cmake/