This module allows the discovery of Pytest scripts and exposes them through CTest.
The advantage of using this module is that you can use a common filtering and configuration mechanism if you use CMake with for example GoogleTest or other tools that also integrate into the CTest runner.
In your CMake include the Pytest.cmake
file, you must enable tests in your project
as well as have a suitable Python installation with Pytest module installed.
project(MyProject)
find_package(Python COMPONENTS Interpreter Development)
enable_testing()
include(Pytest.cmake)
pytest_discover_tests(
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
TEST_PREFIX "UNITTEST_"
TEST_SUFFIX "_${CMAKE_SYSTEM_PROCESSOR}"
XML_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/report
)
For more information see the module itself, it has inline documentation.
During execution tests that are deselected will be marked as skipped, this should only happen
if the collection arguments were different than execution arguments. Skipped tests can also be
picked up by ctest but this requires setting the exit code to 5 when no tests were executed,
something which is not done by pytest
, see issues #812
and #5689.
This can be solved with a few hooks, see example conftest.