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 1/2] 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 8ec08aed8..04320acf4 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 =========================== From 06a9608a248e84bd2fafa4e37c9fd5f377bfe8c0 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Mon, 17 Mar 2025 11:26:55 +0100 Subject: [PATCH 2/2] Link fixes --- docs/reference/quality.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/reference/quality.rst b/docs/reference/quality.rst index 04320acf4..abc73fded 100644 --- a/docs/reference/quality.rst +++ b/docs/reference/quality.rst @@ -160,14 +160,14 @@ 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 +plugin for ``pytest``. The main difference to ``pytest-mypy-plugins`` is that +``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 + :mod:`ast` module to parse candidate files and does not import any file, i.e., the decorator must be exactly named ``@pytest.mark.mypy_testing``!