skillfed

pytest-mypy-plugins

pytest plugin for writing tests for mypy plugins

pytest-mypy-plugins v4.0.3 459.5K downloads/30d#6,541 on PyPI126
Permissive license MIT Active released

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-plugins

uv

uv add pytest-mypy-plugins

poetry

poetry add pytest-mypy-plugins

Installing 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

Development Status :: 5 - Production/StableLicense :: OSI Approved :: MIT LicenseProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Typing :: Typed

Tags

mypy type testing pluginpytest mypy integrationtype checking test frameworkmypy plugin testingyaml type assertion testing
type-checkingmypy-plugintesting-framework

More Testing packages