skillfed

pytest-cmake

Provide CMake module for Pytest

pytest-cmake v1.3.0 269.7K downloads/30d#8,252 on PyPI32
Permissive 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) AGING released

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-cmake

uv

uv add pytest-cmake

poetry

poetry add pytest-cmake

Installing 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

Intended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Topic :: Software Development :: Build Tools

Tags

cmake pytest integrationpython testing in cmakectest pytest discoverycmake find_package pytestc++ python test automationcmake python bindings testing
cmake-integrationmixed-language-testing

More Build Tools packages