From ebbefdbb2504fb39890600b4ee60a50ac1b8deae Mon Sep 17 00:00:00 2001 From: Stavros Ntentos <133706+stdedos@users.noreply.github.com> Date: Mon, 4 Sep 2023 15:01:30 +0300 Subject: [PATCH] Quality: Add https://github.com/davidfritzsche/pytest-mypy-testing as a tool Signed-off-by: Stavros Ntentos <133706+stdedos@users.noreply.github.com> --- docs/source/quality.rst | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/docs/source/quality.rst b/docs/source/quality.rst index 8ec08aed..04320acf 100644 --- a/docs/source/quality.rst +++ b/docs/source/quality.rst @@ -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 `_ 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`_ 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 ===========================