From d1125eb613e3c49c4128e004284e572ad337cad1 Mon Sep 17 00:00:00 2001 From: Elias <110238618+ESadek-MO@users.noreply.github.com> Date: Mon, 4 Nov 2024 11:23:04 +0000 Subject: [PATCH] Add a pytest-unittest translator to the conversion guide (#6213) * added conversion translation section, and fixed mocker reference * mocker is a fixture * which can, not which and * clarified mocker is the fixture, not .patch --- .../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..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("...")``. Note, ``mocker.patch("...")`` is NOT a context manager. + ``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 @@ -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(...)`` +