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

Merge pytesting contributions to main #6207

Merged
merged 89 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
9fd0148
Add pytest-mock dependency (#5811)
bjlittle Mar 11, 2024
7c9c4e1
Updated environment lockfiles
web-flow Mar 11, 2024
fa88fb3
added pytest iris class (#5808)
ESadek-MO Mar 11, 2024
80b42f5
Merge pull request #5812 from SciTools/auto-update-lockfiles
bjlittle Mar 11, 2024
1ca9400
make unit/config pytest (#5810)
stephenworsley Mar 11, 2024
2e7bddc
Convert all tests to pytest.
pp-mo Mar 11, 2024
58d541c
Don't use staticmethod on fixtures.
pp-mo Mar 11, 2024
40cd749
Everything in 'TestConcatenate__dask' can use the same sample cubes.
pp-mo Mar 11, 2024
0f36090
Spurious parentheses in 'pytest.fixture()'
pp-mo Mar 11, 2024
fa86a4f
Convert all tests to pytest.
pp-mo Mar 11, 2024
9aaa71f
Merge pull request #5813 from pp-mo/pytests_unit_concatenate__test_co…
bjlittle Mar 11, 2024
5586c6b
Merge pull request #5816 from pp-mo/pytests_unit_concatenate__test_cu…
bjlittle Mar 11, 2024
9f71331
Rewrite `result_path()` for pytest (#5817)
trexfeathers Mar 12, 2024
e954d73
Configure pytest-mock as pytest required-plugin (#5815)
bjlittle Mar 12, 2024
d807650
pytest migration ruff PT compliance for unit.concatenate (#5823)
bjlittle Mar 12, 2024
d0f4f2b
pytest migration for unit.common.test_Lenient (#5822)
bjlittle Mar 13, 2024
fc4d1aa
Convert to pytest.
pp-mo Mar 13, 2024
096b2b3
Better implementation of `_shared_utils.results_path()` - using PyTes…
trexfeathers Mar 13, 2024
b3eb2d1
Convert to pytest.
pp-mo Mar 13, 2024
5000fd3
Convert to pytest.
pp-mo Mar 14, 2024
f66c885
Merge pull request #5829 from pp-mo/pytests_unit_auxfact__auxcoordfac…
bjlittle Mar 14, 2024
7415bcc
Merge pull request #5834 from pp-mo/pytests_unit_auxfact__atmossigma
bjlittle Mar 14, 2024
dfd25e2
Convert graphics testing conveniences to PyTest (#5832)
trexfeathers Mar 14, 2024
6a5a19f
Simplify data fixtures.
pp-mo Mar 14, 2024
b49a508
Simplify data fixtures.
pp-mo Mar 14, 2024
909bd1a
Simplify data fixtures.
pp-mo Mar 14, 2024
8b8c32b
Simplify Mock usage.
pp-mo Mar 14, 2024
64cdf14
Tidy equality checks.
pp-mo Mar 14, 2024
bed9093
Merge pull request #5838 from pp-mo/pytests_unit_auxfact__atmossigma
bjlittle Mar 14, 2024
f652341
Merge pull request #5836 from pp-mo/pytests_unit_auxfact__hybridpressure
bjlittle Mar 14, 2024
89dd822
Convert to pytest,
pp-mo Mar 14, 2024
985b18c
Merge pull request #5840 from pp-mo/pytests_unit_auxfact__oceans
bjlittle Mar 14, 2024
be3eebf
pytest migration for unit.common.lenient.test__lenient_client (#5842)
bjlittle Mar 15, 2024
114cb5e
pytest migration for unit.common.lenient.test__Lenient (#5828)
bjlittle Mar 15, 2024
2e18ae8
Convert to pytest.
pp-mo Mar 15, 2024
2466ab0
Convert `tests/test_plot` to PyTest (#5839)
trexfeathers Mar 15, 2024
b522f3c
Test aggregate pytest (#5846)
trexfeathers Mar 15, 2024
da88a70
pytest migration for unit.common.lenient.test__lenient_service (#5843)
bjlittle Mar 16, 2024
a12d398
pytest migration for unit.common.mixin.test__get_valid_standard_name …
bjlittle Mar 16, 2024
62e289e
Merge pull request #5848 from pp-mo/pytests_unit_lazydata
bjlittle Mar 18, 2024
f60c5d4
pytest migration for unit.common.mixin.test_CFVariableMixin (#5849)
bjlittle Mar 18, 2024
ed9287f
pytest migration for unit.common.lenient.test__qualname (#5845)
bjlittle Mar 19, 2024
ca9e3f6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 19, 2024
c62264f
pytest migration for unit.common.mixin.test_LimitedAttributeDict (#5851)
bjlittle Mar 19, 2024
b19650d
pytest migration for unit.common.metadata.test_NamedTupleMeta (#5852)
bjlittle Mar 19, 2024
04002bb
Make test_analysis PyTest (#5859)
trexfeathers Mar 19, 2024
dd5036a
Convert to pytest.
pp-mo Mar 19, 2024
37bb689
Convert unit/fileformats/__init__ code to pytest + move to pp_load_ru…
pp-mo Mar 19, 2024
10b21e6
Convert unit/fileformats/pp_load_rules to pytest.
pp-mo Mar 19, 2024
dbc207e
converted cube directory tests to pytest (#5837)
ESadek-MO Mar 19, 2024
ecd1ca3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 19, 2024
8ccb587
Convert tests in unit/util to pytest (#5853)
ESadek-MO Mar 19, 2024
58bb4b1
Use mocker.spy in place of mock.patch.
pp-mo Mar 20, 2024
f906328
Merge pull request #5862 from pp-mo/pytests_unit_fileformats_abf
bjlittle Mar 20, 2024
0c36ec8
pytest migration for unit.common.metadata.test_AncillaryVariableMetad…
bjlittle Mar 20, 2024
e2ea7aa
Merge pull request #5863 from pp-mo/pytests_unit_fileformats__init
bjlittle Mar 20, 2024
de5f027
Convert `unit.plot` and `.quickplot` to PyTest (#5866)
trexfeathers Mar 20, 2024
10177e4
Convert setups to autouse fixtures.
pp-mo Mar 20, 2024
3787f9a
Convert to Pytest.
pp-mo Mar 20, 2024
8f9a226
Convert to Pytest.
pp-mo Mar 20, 2024
0b060ec
Convert to pytest.
pp-mo Mar 20, 2024
73926d2
Convert to pytest, move test_rules into /rules.
pp-mo Mar 20, 2024
2bf9a4b
Merge pull request #5869 from pp-mo/pytests_unit_fileformats_nimrod
bjlittle Mar 20, 2024
c87d500
Convert to pytest
pp-mo Mar 20, 2024
a8a051f
Merge pull request #5865 from pp-mo/pytests_unit_fileformats_pploadrules
bjlittle Mar 20, 2024
745c62f
Merge pull request #5870 from pp-mo/pytests_unit_fileformats_dotpath
bjlittle Mar 20, 2024
62906d0
Merge pull request #5871 from pp-mo/pytests_unit_fileformats_nameloaders
bjlittle Mar 20, 2024
7586325
Merge pull request #5872 from pp-mo/pytests_unit_fileformats_rules
bjlittle Mar 20, 2024
64b47fc
Convert remaining graphics tests to PyTest (#5867)
trexfeathers Mar 21, 2024
9c4a9cc
Convert unit/fileformats/structured_array_identification to pytest.
pp-mo Mar 21, 2024
f76302f
Merge pull request #5877 from pp-mo/pytests_unit_fileformats_structur…
bjlittle Mar 21, 2024
04ed352
Review changes.
pp-mo Mar 21, 2024
6b9b53a
Merge pull request #5873 from pp-mo/pytests_unit_fileformats_cf
bjlittle Mar 22, 2024
f1864a7
pytest migration for unit.common.metadata.test_BaseMetadata (#5868)
bjlittle Mar 22, 2024
ffc0abd
pytest migration of unit.common.metadata.test_hexdigest (#5874)
bjlittle Mar 22, 2024
4c3879b
pytest migration of unit.common.metadata.test_metadata_filter (#5875)
bjlittle Mar 22, 2024
b581b16
pytest migration for unit.common.metadata.test_CubeMetadata (#5881)
bjlittle Mar 22, 2024
47a0cd2
pytest migration of unit.common.metadata.test_metadata_manager_factor…
bjlittle Mar 22, 2024
bd6a9d7
More root pytest (#5883)
trexfeathers Mar 22, 2024
c9b100d
pytest migration of unit.common.metadata.test_CellMeasureMetadata (#5…
bjlittle Mar 22, 2024
fce59c7
pytest migration of unit.common.metadata.test_CoordMetadata (#5880)
bjlittle Mar 27, 2024
3d2ac71
pytest migration of unit.common.resolve.test_Resolve (#5882)
bjlittle Apr 9, 2024
21005f3
Merge remote-tracking branch 'upstream/main' into pytest_merge_conflicts
HGWright Oct 31, 2024
50d1c37
regen lockfiles
HGWright Oct 31, 2024
20bb1e3
precommit fixes
HGWright Oct 31, 2024
40e9a36
fix some test failures
HGWright Oct 31, 2024
00f0e0c
Merge pull request #6209 from HGWright/pytest_merge_conflicts
ESadek-MO Oct 31, 2024
3c63662
Added a style guide for iris pytest (#5785)
ESadek-MO Nov 1, 2024
071ca8e
added whatsnew entries (#6211)
ESadek-MO Nov 1, 2024
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
56 changes: 56 additions & 0 deletions docs/src/developers_guide/contributing_pytest_conversions.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
.. include:: ../common_links.inc

.. _contributing_pytest_conversions:

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

.. code-block:: 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>``.

2 changes: 1 addition & 1 deletion docs/src/developers_guide/contributing_running_tests.rst
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ experimental dependency not being present.
SKIPPED [1] lib/iris/tests/unit/util/test_demote_dim_coord_to_aux_coord.py:29: Test(s) require external data.

All Python decorators that skip tests will be defined in
``lib/iris/tests/__init__.py`` with a function name with a prefix of
``lib/iris/tests/_shared_utils.py`` with a function name with a prefix of
``skip_``.

You can also run a specific test module. The example below runs the tests for
Expand Down
147 changes: 0 additions & 147 deletions docs/src/developers_guide/contributing_testing.rst

This file was deleted.

4 changes: 2 additions & 2 deletions docs/src/developers_guide/contributing_testing_index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ Testing
.. toctree::
:maxdepth: 3

contributing_testing
testing_tools
contributing_tests
contributing_graphics_tests
contributing_running_tests
contributing_ci_tests
contributing_benchmarks
contributing_pytest_conversions
Loading
Loading