Registry / testing / pytest-mypy-plugins

pytest-mypy-plugins

JSON →
library4.0.3pypypiunverified

pytest-mypy-plugins is a pytest plugin designed for writing tests for mypy plugins, stubs, and type definitions. It allows developers to verify the correctness of their type annotations and mypy plugin behavior directly within their pytest test suite. The library is actively maintained, with releases as needed, and the current version is 4.0.1.

pip install pytest-mypy-plugins
INSTALL
IMPORT
SIG · PYTEST-MYPY-PLUGIN
P
pytest-mypy-plugins
testingpythonv4.0.3
Install
6.7s avg
Import
—
Disk
104MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v4.0.3 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 104.2MB
glibc
py 3.10–3.920 runs
installs and imports cleanly · install 6.7s · import 0.000s · 104MB
104MB installed
● package 104MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

pytest-mypy-plugins
✓ No explicit import usually needed, automatically discovered by pytest.
pytest plugins are typically auto-discovered upon installation. For advanced configuration, one might access the plugin via `config.pluginmanager.getplugin('mypy')` in `conftest.py`.

Create a Python file (`my_module.py`) with code to be type-checked, and a YAML file (`test_types.yml`) defining test cases. Each `case` block in the YAML file contains `main` (Python code) and uses `# N:` for expected `reveal_type` output or `# E:` for expected mypy error messages. The plugin automatically discovers and runs these tests when `pytest` is executed.

# Save as my_module.py def add(a: int, b: int) -> int: return a + b # Save as test_types.yml in a directory like 'typesafety/' - case: correct_addition main: | from my_module import add result = add(1, 2) reveal_type(result) # N: Revealed type is 'builtins.int' - case: incorrect_addition_type main: | from my_module import add add(1, '2') # E: Argument 2 to "add" has incompatible type "str"; expected "int" [arg-type] # To run tests, simply execute pytest in your terminal from the project root: # pytest
Debug
Known issues
breakingErrors are now ignored in site-packages by default starting from version 4.0.0.
fix
The `--mypy-only-local-stub` flag was removed. To restore the previous behavior of checking errors in site-packages, use the new `--mypy-no-silence-site-packages` flag.
affects: 4.0.0 and later
breakingPython 3.8 support was dropped in versions 3.2.0 and 3.3.0.
fix
Ensure your test environment uses Python 3.9 or newer. Python 3.13 support was officially added in 3.3.0.
affects: 3.2.0, 3.3.0 and later
breakingPython 3.7 support was dropped starting from version 3.0.0.
fix
Upgrade your Python environment to Python 3.8 or newer. The minimum Python requirement for the latest versions is `>=3.10`.
affects: 3.0.0 and later
gotchaRelative paths in `PYTHONPATH` or `MYPYPATH` environment variables may not work as expected when `mypy` runs in a subprocess (the default mode for the plugin).
fix
Either invoke `pytest` with `--mypy-same-process` to run `mypy` in the same process, or use absolute paths for `PYTHONPATH` and `MYPYPATH` to ensure correct referencing.
affects: All versions
Upgrade
Version history
4.0.3latest on PyPI · released May 14, 2026
Audit
Dependencies
pytestrequiredThis is a pytest plugin and integrates with pytest's test discovery and execution. Requires pytest>=7.0.0.
mypyrequiredThe plugin tests mypy types, stubs, and plugins. It integrates directly with the mypy type checker. Supports mypy@1.8.0 and later versions.
Agent activity
25 hits · last 30 days
node
22
OpenAI (training)
1
Resources
pytest-mypy-plugins — pip install pytest-mypy-plugins · libregistry