Skip to main content

pytest-cppcheck

CI PyPI Python License

A pytest plugin that runs cppcheck static analysis on C/C++ source files. Each file is collected as a test item and reported as a pass or failure in the normal pytest output.

Useful for Python projects with C extension modules where you already run pytest and want cppcheck findings surfaced in the same test run.

Installation

pip install pytest-cppcheck

This pulls in cppcheck automatically via the cppcheck PyPI package. If you prefer a specific version, install cppcheck yourself via your system package manager (apt install cppcheck, brew install cppcheck, etc.) — the plugin uses whichever cppcheck is on PATH.

Usage

The plugin does nothing unless explicitly enabled:

pytest --cppcheck

This collects all .c and .cpp files and runs cppcheck on each one. Files with findings fail; clean files pass.

PASSED src/clean.c::CPPCHECK
FAILED src/buggy.c::CPPCHECK
  src/buggy.c:42:8: error: Array 'arr[10]' accessed at index 10, which is
  out of bounds. [arrayIndexOutOfBounds]

You can combine --cppcheck with your normal test run — Python tests and cppcheck items appear together in the results.

Configuration

All options go in pyproject.toml, pytest.ini, or setup.cfg under [pytest].

cppcheck_args

Extra arguments forwarded to every cppcheck invocation. This is the main configuration surface — use it for --enable, --suppress, and any other cppcheck flags. The plugin always passes --quiet and --error-exitcode=1 automatically.

With no cppcheck_args, cppcheck runs its default checks (mostly error-severity). Use --enable to broaden coverage. A good starting configuration:

[pytest]
cppcheck_args =
    --enable=warning,style,performance,portability
    --check-level=exhaustive

cppcheck_extensions

File extensions to collect. Default: .c .cpp.

[pytest]
cppcheck_extensions = .c .cpp .h

Markers

All cppcheck items are marked with cppcheck, so you can select or exclude them with -m:

pytest --cppcheck -m cppcheck           # only cppcheck
pytest --cppcheck -m "unit or cppcheck" # unit tests + cppcheck
pytest --cppcheck -m "not cppcheck"     # everything except cppcheck

Caching

Results are cached based on file modification time and cppcheck_args. On subsequent runs, files that previously passed are skipped. The cache is automatically invalidated when a file is modified or cppcheck_args changes. Caching relies on pytest's built-in cache provider (the .pytest_cache directory). If the cache provider is disabled (for example with -p no:cacheprovider), results will not be cached and all files will be re-checked on each run.

To force a full re-check:

pytest --cppcheck --cache-clear

License

MIT

Release files for pytest-cppcheck 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytest-cppcheck 0.1.2
File Size Uploaded
pytest_cppcheck-0.1.2.tar.gz 5.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-cppcheck 0.1.2
File Interpreter ABI Platform
pytest_cppcheck-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 11.6 kB

Release files / pytest_cppcheck-0.1.2.tar.gz

Download URL pytest_cppcheck-0.1.2.tar.gz
Size 5.7 kB
Tags Source
SHA-256 checksum
How to use checksums
f51e28ffa204c84849068aa26355e44b6279b2589723a286d0ec4d4d7b82f98b
BLAKE2b-256 checksum
How to use checksums
8ea89b0cb5e9089bde31f903bff2a788d0a4739b6df01d2ddc50f6cf21d82640
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 26, 2026.

Transparency log

Release files / pytest_cppcheck-0.1.2-py3-none-any.whl

Download URL pytest_cppcheck-0.1.2-py3-none-any.whl
Size 5.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e98ba50cc3a5caf916a9228cb73c27d688e314c47260367b4783af2e33dc4c48
BLAKE2b-256 checksum
How to use checksums
6a5a7ccee35a404fc9b1844bf71587a412905f124ba02188da5dcc52768dae12
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 26, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page