A static analysis tool for PHP that finds bugs in code without running it.
realpython/pytest-mypy
A pytest plugin that runs the mypy static type checker on your source files as part of your pytest test runs.
- Stars
- 257
- Forks
- 33
- Open issues
- 8
- Last commit
- 16 days ago
What is it?
pytest-mypy adds mypy type checking to the pytest workflow. When enabled with the --mypy flag, it runs mypy over the Python files you pass to pytest and reports type errors as test results, so type checks run alongside your existing tests. It is modeled on pytest-flake8, which does the same job for flake8.
mypy settings can be provided through a mypy.ini file as usual. The plugin can also be configured from a conftest.py, where extra mypy options such as --check-untyped-defs can be appended to its argument list. Running pytest with -m mypy limits the session to type checks only, skipping other tests.
The project is installed from PyPI with pip and is distributed under the MIT license.
Key features
- 01Runs mypy on source files during pytest runs
- 02Enabled with a single --mypy flag
- 03Reads standard mypy.ini configuration
- 04Accepts extra mypy options from conftest.py
- 05Can restrict a run to type checks only with -m mypy
Use cases
- Catching type errors in a Python project's CI test pipeline
- Enforcing type checks alongside unit tests without a separate tool invocation
- Applying stricter mypy options such as --check-untyped-defs only to the test run
Quick start
- 1
Install the plugin from PyPI with pip
pip install pytest-mypy - 2
Run pytest with the --mypy flag on your test files
py.test --mypy test_*.py
Things to know
- The README says this is a work in progress.
In collections
Topics
FAQ
- What is pytest-mypy?
- A pytest plugin that runs the mypy static type checker on your source files as part of your pytest test runs. pytest-mypy adds mypy type checking to the pytest workflow. When enabled with the --mypy flag, it runs mypy over the Python files you pass to pytest and reports type errors as test results, so type checks run alongside your existing tests. It is modeled on pytest-flake8, which does the same job for flake8.
- Is pytest-mypy free to use? What license does it have?
- pytest-mypy is open source under the MIT license. Check the license terms before using it in commercial products.
- Is pytest-mypy still maintained?
- Actively maintained. The last commit to pytest-mypy was on Oct 22, 2026.
- What can I use pytest-mypy for?
- Catching type errors in a Python project's CI test pipeline Enforcing type checks alongside unit tests without a separate tool invocation Applying stricter mypy options such as --check-untyped-defs only to the test run
- How do I install pytest-mypy?
- Install the plugin from PyPI with pip: pip install pytest-mypy Run pytest with the --mypy flag on your test files: py.test --mypy test_*.py
- Where can I get pytest-mypy?
- The source code and installation instructions are on GitHub: https://github.com/realpython/pytest-mypy
Summary generated by AI from the project's README. GitHub stats refresh daily.
Related projects
A standards-based static type checker for Python, with a command-line tool and a Visual Studio Code extension, built for large codebases.
Pure-Python runtime type checker that enforces PEP type hints on functions, classes and variables with minimal overhead.
Run-time type checker for Python that validates PEP 484 annotations on functions, arbitrary objects, and local variables.
Ruby static analyzer that infers types from code without annotations, aiming to report only conclusive bugs such as undefined methods and nil receivers.
A Python library that records HTTP interactions made during tests and replays them later, so tests run offline and deterministically.