Skip to content

Commit d1125eb

Browse files
authored
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
1 parent 5714ed6 commit d1125eb

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

docs/src/developers_guide/contributing_pytest_conversions.rst

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Conversion Checklist
4141

4242
#. Check for references to ``@tests``. These should be changed to ``@_shared_utils``.
4343
#. Check for references to ``with mock.patch("...")``. These should be replaced with
44-
``mocker.patch("...")``. Note, ``mocker.patch("...")`` is NOT a context manager.
44+
``mocker.patch("...")``. ``mocker`` is a fixture, and can be passed into functions.
4545
#. Check for ``np.testing.assert...``. This can usually be swapped for
4646
``_shared_utils.assert...``.
4747
#. Check for references to ``super()``. Most test classes used to inherit from
@@ -54,3 +54,23 @@ Conversion Checklist
5454
#. Check the file against https://github.com/astral-sh/ruff , using ``pip install ruff`` ->
5555
``ruff check --select PT <file>``.
5656

57+
Common Translations
58+
-------------------
59+
60+
.. list-table::
61+
:widths: 50 50
62+
:header-rows: 1
63+
64+
* - ``unittest`` method
65+
- ``pytest`` equivalent
66+
* - ``assertTrue(x)``
67+
- ``assert x``
68+
* - ``assertFalse(x)``
69+
- ``assert not x``
70+
* - ``assertRegex(x, y)``
71+
- ``assert re.match(y, x)``
72+
* - ``assertRaisesRegex(cls, msg_re)``
73+
- ``with pytest.raises(cls, match=msg_re):``
74+
* - ``mock.patch(...)``
75+
- ``mocker.patch(...)``
76+

0 commit comments

Comments
 (0)