Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a pytest-unittest translator to the conversion guide #6213

Merged
merged 4 commits into from
Nov 4, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion docs/src/developers_guide/contributing_pytest_conversions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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("...")``, which and be passed into functions as a fixture.
ESadek-MO marked this conversation as resolved.
Show resolved Hide resolved
#. 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
Expand All @@ -54,3 +54,23 @@ Conversion Checklist
#. Check the file against https://github.com/astral-sh/ruff , using ``pip install ruff`` ->
``ruff check --select PT <file>``.

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(...)``

Loading