Skip to main content

Use pytest's runner to discover and execute C++ tests

Project description

Supported Python versions version anaconda ci black

Use pytest runner to discover and execute C++ tests.

Supports Google Test, Boost.Test, and Catch2:

This brings several benefits:

  • Allows you to run all your tests in multi-language projects with a single command;

  • Execute C++ tests in parallel using pytest-xdist plugin;

  • Use --junitxml option to produce a single and uniform xml file with all your test suite results;

  • Filter which tests to run using standard test filtering capabilities, such as by file names, directories, keywords by using the -k option, etc.;


Install using pip:

$ pip install pytest-cpp


$ pytest

Once installed, pytest runs will search and run tests found in executable files, detecting if the suites are Google, Boost, or Catch2 tests automatically.

Configuration Options

Following are the options that can be put in the pytest configuration file related to pytest-cpp.


You can configure which files are tested for suites by using the cpp_files ini configuration option:

cpp_files = test_suite*

By default matches test_* and *_test executable files.


Arguments to the C++ tests can be provided with the cpp_arguments ini configuration option.

For example:

cpp_arguments =-v --log-dir=logs

You can change this option directly in the command-line using pytest’s -o option:

$ pytest -o cpp_arguments='-v --log-dir=logs'

Important: do not pass filtering arguments (for example --gtest_filter), as this will conflict with the plugin functionality and behave incorrectly.

To filter tests, use the standard pytest filtering facilities (such as -k).


This option defaults to True and configures the plugin to ignore *.py files that would otherwise match the cpp_files option.

Set it to False if you have C++ executable files that end with the *.py extension.

cpp_ignore_py_files = False


This option allows the usage of tools that are used by invoking them on the console wrapping the test binary, like valgrind and memcheck:

cpp_harness = valgrind --tool=memcheck


This option allows the usage of tools or emulators (like wine or qemu) that are used by invoking them on the console wrapping the test binary during a test collection.

Might be used in the combination with cpp_harness to run a binary in emulators, like wine or qemu in cross-compilation targets.

cpp_harness_collect = qemu-x86_64 -L libs/


cpp_harness_collect = qemu-x86_64 -L libs/
cpp_harness = qemu-x86_64 -L libs/


Please consult CHANGELOG.


All feature requests and bugs are welcome, so please make sure to add feature requests and bugs to the issues page!

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest-cpp-2.5.0.tar.gz (465.0 kB view hashes)

Uploaded source

Built Distribution

pytest_cpp-2.5.0-py3-none-any.whl (15.1 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page