pytest-cpp is a pytest plugin that allows the pytest runner to discover and execute C++ tests. It supports popular frameworks like Google Test, Boost.Test, and Catch2. This integration enables running tests from multi-language projects with a single command, facilitates parallel execution with plugins like pytest-xdist, and provides uniform JUnit XML output. The current version is 2.6.0, with releases typically occurring 1-3 times per year, categorizing its release cadence as 'Slow'.
Install & Compatibility
Where this runs
tested against v2.6.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 30.7MB
glibcpy 3.10–3.920 runs
installs and imports cleanly · install 2.7s · import 0.000s · 31MB
29MB installed
● package 29MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
pytest-cpp operates as a plugin that pytest discovers and loads automatically. User-facing interactions are primarily through pytest's command-line interface and pytest.ini configuration, rather than direct Python imports from the `pytest_cpp` package for its core test discovery and execution features.
pytest automatically discovers and loads the plugin once installed.
After installing `pytest-cpp`, create a C++ test file (e.g., `my_cpp_tests.cpp`) using a supported framework like Google Test. Compile it into an executable (e.g., `test_app`). By default, `pytest-cpp` discovers executables matching `test_*` or `*_test` patterns. Simply run `pytest` in the directory containing your compiled C++ test executable, and `pytest-cpp` will integrate and execute these tests alongside any Python tests.
/* C++ test file: my_cpp_tests.cpp (using Google Test) */
#include <gtest/gtest.h>
TEST(ExampleTest, Succeeds) {
ASSERT_EQ(1, 1);
}
TEST(ExampleTest, Fails) {
ASSERT_EQ(1, 2); // This test will fail
}
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
# Compile the C++ test (example for Linux/macOS with g++ and Google Test)
# g++ my_cpp_tests.cpp -o test_app -I/usr/local/include -L/usr/local/lib -lgtest -lgtest_main -pthread
# (Adjust include/lib paths as needed for your system/build setup)
# To run with pytest-cpp:
# 1. Ensure pytest-cpp is installed: pip install pytest-cpp
# 2. Navigate to the directory containing 'test_app' executable.
# 3. Run pytest:
# pytest
# Example pytest.ini configuration to customize C++ file discovery:
# [pytest]
# cpp_files = my_cpp_test_exec*
# cpp_arguments = -v
# Expected output for the above example (truncated):
# ============================= test session starts =============================
# ...
# collected 2 items
#
# test_app::ExampleTest.Succeeds PASSED [ 50%]
# test_app::ExampleTest.Fails FAILED [100%]
#
# =================================== FAILURES ==================================
# ____________________________ ExampleTest.Fails _____________________________
#
# ASSERT_EQ(1, 2), failed at my_cpp_tests.cpp:10
# Expected: 1
# Actual: 2
#
# =========================== short test summary info ===========================
# FAILED test_app::ExampleTest.Fails - ASSERT_EQ(1, 2), failed at my_cpp_tests.cpp:10
# ========================= 1 failed, 1 passed in ...s =========================
pytest --version
Upgrade
Version history
Breaking-change detection hasn't run for this library yet.
Audit
Security & dependencies
CVE tracking and dependency tree are planned for a later release.