A pytest plugin that runs cpplint style checking 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 cpplint findings surfaced in the same test run.
pip install pytest-cpplint
This pulls in cpplint automatically via the cpplint PyPI package.
The plugin does nothing unless explicitly enabled:
pytest --cpplint
This collects all .c, .cc, .cpp, .cxx, .h, .hpp, and .hxx files
and runs cpplint on each one. Files with findings fail; clean files pass.
PASSED src/clean.c::CPPLINT
FAILED src/buggy.c::CPPLINT
src/buggy.c:12: Lines should be <= 80 characters long [whitespace/line_length] [2]
You can combine --cpplint with your normal test run — Python tests and
cpplint items appear together in the results.
All options go in pyproject.toml, pytest.ini, or setup.cfg under [pytest].
Extra arguments forwarded to every cpplint invocation. This is the main
configuration surface — use it for --filter, --linelength, --root, and
any other cpplint flags.
With no cpplint_args, cpplint runs all of its default checks (Google C++
style guide). Use --filter to enable or disable specific categories. A good
starting configuration:
[pytest]
cpplint_args =
--linelength=120
--filter=-legal/copyright,-build/header_guardFile extensions to collect. Default: .c .cc .cpp .cxx .h .hpp .hxx.
[pytest]
cpplint_extensions = .c .cpp .hAll cpplint items are marked with cpplint, so you can select or exclude
them with -m:
pytest --cpplint -m cpplint # only cpplint
pytest --cpplint -m "unit or cpplint" # unit tests + cpplint
pytest --cpplint -m "not cpplint" # everything except cpplint
Results are cached based on file modification time and cpplint_args. On
subsequent runs, files that previously passed are skipped. The cache is
automatically invalidated when a file is modified or cpplint_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 --cpplint --cache-clear
MIT