Pytest plugin to check mypy output.
pytest-mypy-testing — Plugin to test mypy output with pytest
python -m pip install pytest-mypy-testing
The Python distribution package contains an entry
so that the plugin is automatically discovered by pytest. To disable
the plugin when it is installed , you can use the pytest command line
Writing Mypy Output Test Cases
A mypy test case is a top-level functions decorated with
@pytest.mark.mypy_testing in a file named
*.mypy-testing or in a
pytest test module.
pytest-mypy-testing follows the pytest logic in
identifying test modules and respects the
pytest-mypy-testing uses the Python
ast module to parse
candidate files and does not import any file, i.e., the decorator must
be exactly named
In a pytest test module file you may combine both regular pytest test functions and mypy test functions. A single function can be both.
Example: A simple mypy test case could look like this:
@pytest.mark.mypy_testing def mypy_test_invalid_assginment() -> None: foo = "abc" foo = 123 # E: Incompatible types in assignment (expression has type "int", variable has type "str")
The plugin runs mypy for every file containing at least one mypy test case. The mypy output is then compared to special Python comments in the file:
# N: <msg>- we expect a mypy note message
# W: <msg>- we expect a mypy warning message
# E: <msg>- we expect a mypy error message
# R: <msg>- we expect a mypy note message
Revealed type is '<msg>'. This is useful to easily check
@pytest.mark.mypy_testing def mypy_use_reveal_type(): reveal_type(123) # N: Revealed type is 'Literal?' reveal_type(456) # R: Literal?
Skipping and Expected Failures
Mypy test case functions can be decorated with
@pytest.mark.xfail to mark them as to-be-skipped and as
expected-to-fail, respectively. As with the
@pytest.mark.mypy_testing mark, the names must match exactly as the
decorators are extracted from the ast.
- Create and activate a Python virtual environment.
- Install development dependencies by calling
python -m pip install -U -r requirements.txt.
- Start developing.
- To run all tests with tox, Python 3.6, 3.7 and 3.8 must be available. You might want to look into using pyenv.
PYTEST_VERSION_INFO- by @blueyed (#8)
- Always pass
--check-untyped-defsto mypy (#11)
- Respect pytest config
python_fileswhen identifying pytest test modules (#12)
v0.0.6 - add pytest 5.4 support
- Update the plugin to work with pytest 5.4 (#7)
v0.0.5 - CI improvements
- Make invoke tasks work (partially) on Windows (#6)
- Add an invoke task to run tox environments by selecting globs (e.g.,
inv tox -e py-*) (#6)
- Use coverage directly for code coverage to get more consistent parallel run results (#6)
- Use flit fork dflit to make packaging work with
- Bump dependencies (#6)
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size||File type||Python version||Upload date||Hashes|
|Filename, size pytest_mypy_testing-0.0.7-py3-none-any.whl (20.1 kB)||File type Wheel||Python version py3||Upload date||Hashes View|
|Filename, size pytest-mypy-testing-0.0.7.tar.gz (25.6 kB)||File type Source||Python version None||Upload date||Hashes View|
Hashes for pytest_mypy_testing-0.0.7-py3-none-any.whl
Hashes for pytest-mypy-testing-0.0.7.tar.gz