pytest-cython
A plugin for testing Cython extension modules.
What it is and what it does
pytest-cython is a pytest plugin that extends pytest's doctest discovery and execution to Cython `.pyx` source files. It allows you to write and run doctests directly in docstrings of Cython extension modules, treating them as executable documentation that pytest can validate. This bridges the gap between Cython's compiled C/C++ extensions and Python's standard doctest workflow, letting developers verify that code examples in their Cython module documentation actually work.
The plugin integrates seamlessly with pytest's command-line interface via the `--doctest-cython` flag. It has a single runtime dependency on pytest itself, making installation straightforward. Compatibility is versioned: the current 0.4.x release targets pytest 9 and Cython 3. The package has been maintained since 2016 and remains actively developed, with no known security vulnerabilities.
Use it for:
- Verify that code examples in Cython module docstrings execute correctly as part of your test suite.
- Document C/C++ extension behavior through executable examples without maintaining separate test files.
- Catch documentation drift in Cython projects by running doctests alongside unit tests in CI/CD.
- Test the public API of compiled Cython modules by embedding doctests in `.pyx` files.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
A pytest plugin that runs doctests embedded in Cython `.pyx` extension modules, enabling documentation-driven testing of C/C++ code compiled through Cython.
Yes, if you maintain Cython extensions and want to validate embedded documentation. The plugin is low-friction (one dependency, pure Python), actively maintained, and has no security issues. The main caveat: license terms are undocumented in the package metadata—verify the actual license in the repository before use in proprietary or restricted contexts. Not applicable if you don't use Cython or don't write doctests.
Install
pytest-cython on PyPI
pip
pip install pytest-cythonuv
uv add pytest-cythonpoetry
poetry add pytest-cythonInstalling pytest-cython
Before you install
Low friction: pure Python wheel with only pytest as a runtime dependency. Active maintenance with a recent release (156 days ago) and no known vulnerabilities.
License in practice
License status is unclear—no SPDX identifier or raw license text is recorded. Verify the actual license terms in the repository before adopting in a commercial or restricted context.
Quickstart
pip install pytest-cython
# In your project, run:
pytest --doctest-cython
# Or for a specific .pyx file:
pytest --doctest-cython path/to/module.pyx
Requires Python >=3.8. The --import-mode=importlib option is not supported; --import-mode=prepend with non-editable packages requires PY_IGNORE_IMPORTMISMATCH=1 environment variable.
Verify before relying
- Whether the package is actually licensed under an open-source or proprietary license (license metadata is missing).
- Real-world compatibility with Cython 3.x versions beyond the documented 0.4.x / Cython 3 pairing.
- Whether doctests in compiled .pyx modules execute with the same semantics as Python doctests.
Package facts
| License | not declared (unclear) |
| Python support | supports the current Python release (>=3.8) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — pytest |
| Maintenance | actively maintained — 156 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 281,417/month — #8,097 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: pytest_cython-0.4.0-py3-none-any.whl
Keywords: pytest, py.test, cython, doctest
Tags
More Utilities packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
charset-normalizerDetects and normalizes text encoding from…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
PygmentsPygments is a syntax highlighter that colorizes…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
pytest-loggingA pytest plugin that configures Python logging…
permissive · top 15,000 on PyPI
xdoctestXdoctest finds and executes test code embedded…
permissive · top 5,000 on PyPI
pytest-doctestplusA pytest plugin that runs doctests in Python…
permissive · top 15,000 on PyPI
pytest-helpers-namespaceProvides a pytest namespace for registering and…
permissive · top 15,000 on PyPI
pytest-xmlA pytest plugin that generates XML output from…
unclear · top 15,000 on PyPI
pytest-xvfbA pytest plugin that automatically runs tests…
permissive · top 15,000 on PyPI
pytest-jsonA pytest plugin that generates JSON reports of…
permissive · top 15,000 on PyPI
pytest-snapshotA pytest plugin that enables snapshot…
permissive · top 5,000 on PyPI
pytest-custom-exit-codeA pytest plugin that lets you customize the…
permissive · top 5,000 on PyPI
pytest-richA pytest plugin that uses rich to format and…
permissive · top 15,000 on PyPI