From 8c52324b2d857011c990150e89121693db9b970b Mon Sep 17 00:00:00 2001 From: Elias Sadek Date: Fri, 1 Nov 2024 16:16:38 +0000 Subject: [PATCH 1/4] added conversion translation section, and fixed mocker reference --- .../contributing_pytest_conversions.rst | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/docs/src/developers_guide/contributing_pytest_conversions.rst b/docs/src/developers_guide/contributing_pytest_conversions.rst index c6bb35c2cd..a8d67c3c6f 100644 --- a/docs/src/developers_guide/contributing_pytest_conversions.rst +++ b/docs/src/developers_guide/contributing_pytest_conversions.rst @@ -41,7 +41,7 @@ Conversion Checklist #. Check for references to ``@tests``. These should be changed to ``@_shared_utils``. #. Check for references to ``with mock.patch("...")``. These should be replaced with - ``mocker.patch("...")``. Note, ``mocker.patch("...")`` is NOT a context manager. + ``mocker.patch("...")``. #. Check for ``np.testing.assert...``. This can usually be swapped for ``_shared_utils.assert...``. #. Check for references to ``super()``. Most test classes used to inherit from @@ -54,3 +54,23 @@ Conversion Checklist #. Check the file against https://github.com/astral-sh/ruff , using ``pip install ruff`` -> ``ruff check --select PT ``. +Common Translations +------------------- + +.. list-table:: + :widths: 50 50 + :header-rows: 1 + + * - ``unittest`` method + - ``pytest`` equivalent + * - ``assertTrue(x)`` + - ``assert x`` + * - ``assertFalse(x)`` + - ``assert not x`` + * - ``assertRegex(x, y)`` + - ``assert re.match(y, x)`` + * - ``assertRaisesRegex(cls, msg_re)`` + - ``with pytest.raises(cls, match=msg_re):`` + * - ``mock.patch(...)`` + - ``mocker.patch(...)`` + From 18c5ed5bcf77d4ee09219a884e53aa55aa3119e6 Mon Sep 17 00:00:00 2001 From: Elias Sadek Date: Fri, 1 Nov 2024 16:22:39 +0000 Subject: [PATCH 2/4] mocker is a fixture --- docs/src/developers_guide/contributing_pytest_conversions.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/developers_guide/contributing_pytest_conversions.rst b/docs/src/developers_guide/contributing_pytest_conversions.rst index a8d67c3c6f..92e537dd2b 100644 --- a/docs/src/developers_guide/contributing_pytest_conversions.rst +++ b/docs/src/developers_guide/contributing_pytest_conversions.rst @@ -41,7 +41,7 @@ Conversion Checklist #. Check for references to ``@tests``. These should be changed to ``@_shared_utils``. #. Check for references to ``with mock.patch("...")``. These should be replaced with - ``mocker.patch("...")``. + ``mocker.patch("...")``, which and be passed into functions as a fixture. #. Check for ``np.testing.assert...``. This can usually be swapped for ``_shared_utils.assert...``. #. Check for references to ``super()``. Most test classes used to inherit from From 6067c9fb6d38ca7ae5747e73266b4abd527e61f5 Mon Sep 17 00:00:00 2001 From: Elias Sadek Date: Fri, 1 Nov 2024 16:24:58 +0000 Subject: [PATCH 3/4] which can, not which and --- docs/src/developers_guide/contributing_pytest_conversions.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/developers_guide/contributing_pytest_conversions.rst b/docs/src/developers_guide/contributing_pytest_conversions.rst index 92e537dd2b..e258307721 100644 --- a/docs/src/developers_guide/contributing_pytest_conversions.rst +++ b/docs/src/developers_guide/contributing_pytest_conversions.rst @@ -41,7 +41,7 @@ Conversion Checklist #. Check for references to ``@tests``. These should be changed to ``@_shared_utils``. #. Check for references to ``with mock.patch("...")``. These should be replaced with - ``mocker.patch("...")``, which and be passed into functions as a fixture. + ``mocker.patch("...")``, which can be passed into functions as a fixture. #. Check for ``np.testing.assert...``. This can usually be swapped for ``_shared_utils.assert...``. #. Check for references to ``super()``. Most test classes used to inherit from From c4d20435a2d3a8f1c066a23adb8f71a49061de64 Mon Sep 17 00:00:00 2001 From: Elias <110238618+ESadek-MO@users.noreply.github.com> Date: Mon, 4 Nov 2024 11:10:01 +0000 Subject: [PATCH 4/4] clarified mocker is the fixture, not .patch --- docs/src/developers_guide/contributing_pytest_conversions.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/developers_guide/contributing_pytest_conversions.rst b/docs/src/developers_guide/contributing_pytest_conversions.rst index e258307721..dd556154e7 100644 --- a/docs/src/developers_guide/contributing_pytest_conversions.rst +++ b/docs/src/developers_guide/contributing_pytest_conversions.rst @@ -41,7 +41,7 @@ Conversion Checklist #. Check for references to ``@tests``. These should be changed to ``@_shared_utils``. #. Check for references to ``with mock.patch("...")``. These should be replaced with - ``mocker.patch("...")``, which can be passed into functions as a fixture. + ``mocker.patch("...")``. ``mocker`` is a fixture, and can be passed into functions. #. Check for ``np.testing.assert...``. This can usually be swapped for ``_shared_utils.assert...``. #. Check for references to ``super()``. Most test classes used to inherit from