Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quality: Add https://github.com/davidfritzsche/pytest-mypy-testing as a tool #1461

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions docs/source/quality.rst
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,45 @@ This is an example of a parametrized test with ``pytest-mypy-plugins``:
main: |
reveal_type({[ val }}) # N: Revealed type is '{{ rt }}'

pytest-mypy-testing
-------------------

`pytest-mypy-testing <https://github.com/davidfritzsche/pytest-mypy-testing>`_ is another
plugin for ``pytest``. The main difference between :ref:`pytest-mypy-plugins` is that
:ref:`pytest-mypy-testing` allows writing tests inside Python code and/or
mixed with actual tests.

.. warning::

pytest-mypy-testing uses the Python
`ast<https://docs.python.org/3/library/ast.html>`_ module to parse
candidate files and does not import any file, i.e., the decorator must be
exactly named ``@pytest.mark.mypy_testing``!


These are examples of testing with ``pytest-mypy-testing``:

.. code-block:: python

@pytest.mark.mypy_testing
def mypy_use_reveal_type():
reveal_type(123) # N: Revealed type is 'Literal[123]?'
reveal_type(456) # R: Literal[456]?

.. code-block:: python

def foo(num: int) -> str:
return str(num)


@pytest.mark.mypy_testing
def test_foo():
result = foo(1)
reveal_type(result) # R: builtins.str

assert result == "1"


Improving Type Completeness
===========================

Expand Down