pytest-mypy-plugins
pytest plugin for writing tests for mypy plugins
What it is and what it does
pytest-mypy-plugins is a pytest plugin that lets you write type-checking tests in YAML format, asserting what types mypy infers for your code. Instead of manually running mypy and inspecting output, you define test cases with Python code snippets and expected type annotations inline, then run pytest to validate them. It supports both custom reveal_type matchers and standard typing.assert_type assertions, parametrized test cases, environment variables, and mypy configuration overrides.
The plugin is designed for testing mypy plugins themselves, type stubs, and type-annotated libraries. It handles subprocess isolation by default (running mypy in separate processes) and provides options for same-process debugging. Test cases are written declaratively in YAML with properties like main code, extra files, mypy config, environment variables, and skip/xfail conditions, making it easy to maintain a suite of type-safety regression tests without writing boilerplate Python test code.
Use it for:
- Testing a custom mypy plugin by defining type-checking scenarios in YAML and verifying mypy's behavior
- Validating type stubs for a library by asserting inferred types match expectations across different code patterns
- Regression testing type annotations in a typed library by running a suite of type assertions as part of CI
- Debugging mypy behavior by using --mypy-same-process to inspect type inference in the same Python process
- Parametrized type testing by running the same type assertion across multiple input values or configurations
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
A pytest plugin that runs type-checking tests against mypy by defining test cases in YAML files with inline type assertions and custom matchers.
Yes. This is a well-maintained, production-stable tool with low install friction and no known vulnerabilities. Install it if you maintain a mypy plugin, publish type stubs, or want to add type-safety regression tests to a typed library. The YAML-based test format is more readable and maintainable than writing pytest tests for type checking manually.
Install
pytest-mypy-plugins on PyPI
pip
pip install pytest-mypy-pluginsuv
uv add pytest-mypy-pluginspoetry
poetry add pytest-mypy-pluginsInstalling pytest-mypy-plugins
Before you install
Low friction install with a stable, actively maintained codebase. Nine runtime dependencies are all widely used and well-established (pytest, mypy, pyyaml, jsonschema, Jinja2, decorator, packaging, regex, tomlkit), and the package itself is marked Production/Stable with recent activity.
License in practice
MIT license is permissive; you can use this package freely in commercial and private projects with minimal restrictions.
Quickstart
pip install pytest-mypy-plugins
# Create a test file (e.g., test_types.yml):
# - case: simple_type_check
# main: |
# x = 1
# reveal_type(x) # N: Revealed type is 'builtins.int'
pytest
Requires Python 3.10 or later and mypy to be installed (included as a runtime dependency).
Verify before relying
- Whether the plugin works with all mypy plugin types or only a subset
- Performance characteristics when running large test suites with many YAML cases
- Compatibility with recent mypy versions beyond what the dependency specification guarantees
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 9 — Jinja2, decorator, jsonschema, mypy, packaging, pytest, pyyaml, regex, tomlkit |
| Maintenance | actively maintained — 92 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 459,503/month — #6,541 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: pytest_mypy_plugins-4.0.3-py3-none-any.whl
Tags
More Testing packages
Pluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
virtualenvvirtualenv creates isolated Python environments…
permissive · top 100 on PyPI
coverageCoverage.py measures which lines of Python code…
permissive · top 1,000 on PyPI
pytest-asynciopytest-asyncio is a pytest plugin that enables…
permissive · top 1,000 on PyPI
pytest-json-ctrfA pytest plugin that generates test reports in…
permissive · top 1,000 on PyPI
pytest-regexA pytest plugin that selects tests to run using…
permissive · top 15,000 on PyPI
django-typesProvides type stubs for Django to enable static…
permissive · top 5,000 on PyPI
re-assertProvides a helper class for regex assertions…
permissive · top 15,000 on PyPI
grpc-stubsProvides type stubs for gRPC Python, enabling…
permissive · top 5,000 on PyPI
pytest-datadirA pytest plugin that provides fixtures for…
permissive · top 5,000 on PyPI
pytest-isortA pytest plugin that automatically checks…
permissive · top 15,000 on PyPI
pytest-envA pytest plugin that loads environment…
permissive · top 1,000 on PyPI
django-stubsProvides type stubs and a mypy plugin to enable…
permissive · top 5,000 on PyPI
assertpyProvides a fluent assertion API for writing…
permissive · top 5,000 on PyPI
mypy-strict-kwargsA mypy plugin that enforces…
permissive · top 15,000 on PyPI