Skip to main content

A pytest plugin that runs cppcheck static analysis on C/C++ source files

Project description

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

Project details


Download files

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

Source Distribution

pytest_cppcheck-0.1.2.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_cppcheck-0.1.2-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

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

Hashes for pytest_cppcheck-0.1.2.tar.gz
Algorithm Hash digest
SHA256 f51e28ffa204c84849068aa26355e44b6279b2589723a286d0ec4d4d7b82f98b
MD5 711c6aa48899b8f63fc30b18ffb0d5bc
BLAKE2b-256 8ea89b0cb5e9089bde31f903bff2a788d0a4739b6df01d2ddc50f6cf21d82640

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_cppcheck-0.1.2.tar.gz:

Publisher: release.yml on alexdej/pytest-cppcheck

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytest_cppcheck-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_cppcheck-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e98ba50cc3a5caf916a9228cb73c27d688e314c47260367b4783af2e33dc4c48
MD5 cc21704da91e0170b42aa46f3c2830d4
BLAKE2b-256 6a5a7ccee35a404fc9b1844bf71587a412905f124ba02188da5dcc52768dae12

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_cppcheck-0.1.2-py3-none-any.whl:

Publisher: release.yml on alexdej/pytest-cppcheck

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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