pytest-cmake
Provide CMake module for Pytest
What it is and what it does
pytest-cmake is a CMake module that bridges Pytest and CMake, allowing Python tests to be discovered and run as part of a C++ project's build system. It provides a find_package function to locate Pytest and a pytest_discover_tests function that automatically converts Python tests into CTest entries, which can then be executed and reported alongside native C++ tests.
The package is designed for mixed-language projects—particularly those with C++ libraries that expose Python bindings. Instead of running Python tests separately, developers can integrate them into their CMake workflow, controlling test environment variables like library and Python paths, filtering test names, and declaring dependencies on compiled targets.
Use it for:
- Integrate Python unit tests for C++ extension modules into a unified CMake test suite
- Automatically discover and register Python tests as CTest entries without manual configuration
- Set up controlled test environments by prepending library and Python paths before test execution
- Run mixed C++ and Python tests in a single CI/CD pipeline using ctest
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Integrates Pytest with CMake build systems, enabling automatic discovery and execution of Python tests as part of C++ project builds.
Yes, if you maintain a CMake project with Python tests or C++ code with Python bindings. The package has low install friction, permissive licensing, and no known vulnerabilities. The aging maintenance status is a minor concern for a stable, narrowly-scoped integration tool, but the repository remains active and supports current Python versions.
Install
pytest-cmake on PyPI
pip
pip install pytest-cmakeuv
uv add pytest-cmakepoetry
poetry add pytest-cmakeInstalling pytest-cmake
Before you install
Low friction install with a single runtime dependency on pytest. Last release was 223 days ago; repository is active but aging.
License in practice
MIT License permits unrestricted use, modification, and distribution with minimal restrictions—suitable for both open-source and proprietary projects.
Quickstart
pip install pytest-cmake
In CMakeLists.txt:
find_package(Pytest 8.2.1 REQUIRED)
pytest_discover_tests(PythonTest LIBRARY_PATH_PREPEND $<TARGET_FILE_DIR:MyLibrary>)
Requires CMake and pytest to be installed; pytest-cmake is a CMake module, not a standalone Python tool
Verify before relying
- Whether the package works with pytest versions outside the range shown in the description example (8.2.1)
- Performance characteristics when discovering large numbers of Python tests in a single CMake project
Package facts
| License | MIT License Copyright (c) 2022 Jeremy Retailleau Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to… (full text in the JSON record) (permissive) |
| Python support | supports the current Python release (<4,>=3.7) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — pytest |
| Maintenance | aging — 223 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 269,703/month — #8,252 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: pytest_cmake-1.3.0-py3-none-any.whl
Keywords: cmake, development, pytest
Tags
More Build Tools packages
Provides reusable utilities for Python…
permissive · top 100 on PyPI
tqdmWraps any iterable to display a real-time…
copyleft · top 100 on PyPI
pippip is the standard installer for Python…
permissive · top 100 on PyPI
hatchlingHatchling is a standards-compliant Python build…
permissive · top 100 on PyPI
grpcio-toolsGenerates Python gRPC service stubs and message…
permissive · top 1,000 on PyPI
pre-commitpre-commit is a framework for installing and…
permissive · top 1,000 on PyPI
cmakeDistributes CMake 4.4.2 as a Python package,…
permissive · top 5,000 on PyPI
google-benchmarkProvides Python bindings to Google's C++…
permissive · top 15,000 on PyPI
fckitlibProvides Fortran modules and a unit testing…
unclear · top 15,000 on PyPI
cmakelangProvides command-line tools to format, lint,…
copyleft · top 5,000 on PyPI
colcon-cmakecolcon-cmake is a plugin for colcon that adds…
permissive · top 15,000 on PyPI
scikit-build-coreA build backend that uses CMake to compile…
permissive · top 5,000 on PyPI
cmake-formatFormats, lints, and annotates CMake listfiles,…
copyleft · top 15,000 on PyPI
scikit-buildscikit-build bridges setuptools and CMake to…
permissive · top 5,000 on PyPI
pytest-mypyIntegrates mypy static type checking into…
permissive · top 15,000 on PyPI
cmakelintcmakelint parses CMake files and reports style…
permissive · top 15,000 on PyPI