-
Notifications
You must be signed in to change notification settings - Fork 315
Added a style guide for iris pytest #5785
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
Merged
trexfeathers
merged 16 commits into
SciTools:FEATURE_pytest_conversion
from
ESadek-MO:pytest-conventions
Nov 1, 2024
Merged
Changes from 10 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
9a4a45b
Added a draft style guide for iris pytest
ESadek-MO ba9be1f
most review comments
ESadek-MO 744f1c3
refactored documentation
ESadek-MO 37a342f
fixed doclinks
ESadek-MO a33b44c
reslolved review comments
ESadek-MO ff4eda1
removed excess pages
ESadek-MO 48fbf96
conversion checklist
ESadek-MO 0052a4d
pre-lunch changes
ESadek-MO c491d12
majority review requests, rough reshuffle of Test Categories
ESadek-MO 2267963
further reshuffle of Test Categories
ESadek-MO f2b77e9
review stuffies
ESadek-MO 79c7fc0
Merge branch 'FEATURE_pytest_conversion' into pytest-conventions
trexfeathers 7e6a0bb
fixed a coup of review comments
ESadek-MO 0d370d0
Merge branch 'pytest-conventions' of github.com:ESadek-MO/iris into p…
ESadek-MO 7d07be2
fixed a doctest failures
ESadek-MO 28aa24b
reworded function and class intros
ESadek-MO File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
docs/src/developers_guide/contributing_pytest_conversions.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| .. include:: ../common_links.inc | ||
|
|
||
| .. _converting_from_unittest: | ||
|
|
||
| ******************************************* | ||
| Converting From ``unittest`` to ``pytest`` | ||
| ******************************************* | ||
|
|
||
| Conversion Checklist | ||
| -------------------- | ||
| .. note:: | ||
| Please bear in mind the following checklist is for general use; there may be | ||
| some cases which require extra context or thought before implementing these changes. | ||
|
|
||
| #. Before making any manual changes, run https://github.com/dannysepler/pytestify | ||
| on the file. This does a lot of the brunt work for you! | ||
| #. Check for references to :class:`iris.tests.IrisTest`. If a class inherits | ||
| from this, remove the inheritance. Inheritance is unnecessary for | ||
| pytest tests, so :class:`iris.tests.IrisTest` has been deprecated | ||
| and its convenience methods have been moved to the | ||
| :mod:`iris.tests._shared_utils` module. | ||
| #. Check for references to ``unittest``. Many of the functions within unittest | ||
| are also in pytest, so often you can just change where the function is imported | ||
| from. | ||
| #. Check for references to ``self.assert``. Pytest has a lighter-weight syntax for | ||
| assertions, e.g. ``assert x == 2`` instead of ``assertEqual(x, 2)``. In the | ||
| case of custom :class:`~iris.tests.IrisTest` assertions, the majority of these | ||
| have been replicated in | ||
| :mod:`iris.tests._shared_utils`, but with snake_case instead of camelCase. | ||
| Some :class:`iris.tests.IrisTest` assertions have not been converted into | ||
| :mod:`iris.tests._shared_utils`, as these were deemed easy to achieve via | ||
| simple ``assert ...`` statements. | ||
| #. Check for references to ``setUp()``. Replace this with ``_setup()`` instead. | ||
| Ensure that this is decorated with ``@pytest.fixture(autouse=True)``. | ||
| .. codeblock:: python | ||
|
|
||
| @pytest.fixture(autouse=True) | ||
| def _setup(self): | ||
| ... | ||
|
|
||
| #. 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. | ||
| #. 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 | ||
| :class:`iris.tests.IrisTest`, so references to this should be removed. | ||
| #. Check for references to ``self.tmp_dir``. In pytest, ``tmp_path`` is used instead, | ||
| and can be passed into functions as a fixture. | ||
| #. Check for ``if __name__ == 'main'``. This is no longer needed with pytest. | ||
| #. Check for ``mock.patch("warnings.warn")``. This can be replaced with | ||
| ``pytest.warns(match=message)``. | ||
| #. Check the file against https://github.com/astral-sh/ruff , using ``pip install ruff`` -> | ||
| ``ruff check --select PT <file>``. | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.