A pytest plugin that runs cppcheck static analysis on C/C++ source files
Project description
pytest-cppcheck
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pytest_cppcheck-0.1.2.tar.gz.
File metadata
- Download URL: pytest_cppcheck-0.1.2.tar.gz
- Upload date:
- Size: 5.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f51e28ffa204c84849068aa26355e44b6279b2589723a286d0ec4d4d7b82f98b
|
|
| MD5 |
711c6aa48899b8f63fc30b18ffb0d5bc
|
|
| BLAKE2b-256 |
8ea89b0cb5e9089bde31f903bff2a788d0a4739b6df01d2ddc50f6cf21d82640
|
Provenance
The following attestation bundles were made for pytest_cppcheck-0.1.2.tar.gz:
Publisher:
release.yml on alexdej/pytest-cppcheck
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pytest_cppcheck-0.1.2.tar.gz -
Subject digest:
f51e28ffa204c84849068aa26355e44b6279b2589723a286d0ec4d4d7b82f98b - Sigstore transparency entry: 1186606577
- Sigstore integration time:
-
Permalink:
alexdej/pytest-cppcheck@fd6518a6091d37f5fccb04d2d64d0442e63571ac -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/alexdej
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@fd6518a6091d37f5fccb04d2d64d0442e63571ac -
Trigger Event:
push
-
Statement type:
File details
Details for the file pytest_cppcheck-0.1.2-py3-none-any.whl.
File metadata
- Download URL: pytest_cppcheck-0.1.2-py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e98ba50cc3a5caf916a9228cb73c27d688e314c47260367b4783af2e33dc4c48
|
|
| MD5 |
cc21704da91e0170b42aa46f3c2830d4
|
|
| BLAKE2b-256 |
6a5a7ccee35a404fc9b1844bf71587a412905f124ba02188da5dcc52768dae12
|
Provenance
The following attestation bundles were made for pytest_cppcheck-0.1.2-py3-none-any.whl:
Publisher:
release.yml on alexdej/pytest-cppcheck
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pytest_cppcheck-0.1.2-py3-none-any.whl -
Subject digest:
e98ba50cc3a5caf916a9228cb73c27d688e314c47260367b4783af2e33dc4c48 - Sigstore transparency entry: 1186606631
- Sigstore integration time:
-
Permalink:
alexdej/pytest-cppcheck@fd6518a6091d37f5fccb04d2d64d0442e63571ac -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/alexdej
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@fd6518a6091d37f5fccb04d2d64d0442e63571ac -
Trigger Event:
push
-
Statement type: