From 85e5a2f21bc5998c250d7a5fe1b8b2e5a1b74002 Mon Sep 17 00:00:00 2001 From: Richard Shaw Date: Mon, 5 Feb 2024 16:44:27 -0800 Subject: [PATCH] test: ensure tests work with pytest 8.0 This swaps from using the pytest-lazy-fixture plugin to the pytest-lazy-fixtures plugin which supports the underlying changes in pytest 8. --- .github/workflows/main.yml | 4 +- caput/tests/test_memh5.py | 60 +++++++++++++------------- caput/tests/test_memh5_parallel.py | 10 ++--- caput/tests/test_mpiarray.py | 6 +-- caput/tests/test_selection.py | 10 ++--- caput/tests/test_selection_parallel.py | 6 +-- 6 files changed, 48 insertions(+), 48 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a885960c..5545ca83 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -26,7 +26,7 @@ jobs: - name: Install pip dependencies run: | - pip install ruff pytest black mpi4py pyinstrument psutil pytest-lazy-fixture + pip install ruff pytest black mpi4py pyinstrument psutil pytest-lazy-fixtures pip install -r requirements.txt pip install -e .[compression] @@ -62,7 +62,7 @@ jobs: pip install -r requirements.txt pip install zarr==2.11.3 pip install mpi4py numcodecs>=0.7.3 bitshuffle - pip install pytest pytest-lazy-fixture + pip install pytest pytest-lazy-fixtures pip install -e . - name: Run serial tests diff --git a/caput/tests/test_memh5.py b/caput/tests/test_memh5.py index c09bb06c..abcd818b 100644 --- a/caput/tests/test_memh5.py +++ b/caput/tests/test_memh5.py @@ -10,7 +10,7 @@ import h5py import numpy as np import pytest -from pytest_lazyfixture import lazy_fixture +from pytest_lazy_fixtures import lf import zarr import copy @@ -183,8 +183,8 @@ def assertAttrsEqual(a, b): @pytest.mark.parametrize( "test_file,file_open_function", [ - (lazy_fixture("filled_h5_file"), h5py.File), - (lazy_fixture("filled_zarr_file"), zarr.open_group), + (lf("filled_h5_file"), h5py.File), + (lf("filled_zarr_file"), zarr.open_group), ], ) def test_file_sanity(test_file, file_open_function): @@ -196,12 +196,12 @@ def test_file_sanity(test_file, file_open_function): @pytest.mark.parametrize( "test_file,file_open_function,file_format", [ - (lazy_fixture("filled_h5_file"), h5py.File, None), - (lazy_fixture("filled_zarr_file"), zarr.open_group, None), - (lazy_fixture("filled_zarrzip_file"), zarr.open_group, None), - (lazy_fixture("filled_h5_file"), h5py.File, fileformats.HDF5), - (lazy_fixture("filled_zarr_file"), zarr.open_group, fileformats.Zarr), - (lazy_fixture("filled_zarrzip_file"), zarr.open_group, fileformats.Zarr), + (lf("filled_h5_file"), h5py.File, None), + (lf("filled_zarr_file"), zarr.open_group, None), + (lf("filled_zarrzip_file"), zarr.open_group, None), + (lf("filled_h5_file"), h5py.File, fileformats.HDF5), + (lf("filled_zarr_file"), zarr.open_group, fileformats.Zarr), + (lf("filled_zarrzip_file"), zarr.open_group, fileformats.Zarr), ], ) def test_to_from_file(test_file, file_open_function, file_format): @@ -223,8 +223,8 @@ def test_to_from_file(test_file, file_open_function, file_format): @pytest.mark.parametrize( "test_file,file_format", [ - (lazy_fixture("filled_h5_file"), fileformats.HDF5), - (lazy_fixture("filled_zarr_file"), fileformats.Zarr), + (lf("filled_h5_file"), fileformats.HDF5), + (lf("filled_zarr_file"), fileformats.Zarr), ], ) def test_memdisk(test_file, file_format): @@ -253,8 +253,8 @@ def test_memdisk(test_file, file_format): @pytest.mark.parametrize( "test_file,file_format", [ - (lazy_fixture("filled_h5_file"), fileformats.HDF5), - (lazy_fixture("filled_zarr_file"), fileformats.Zarr), + (lf("filled_h5_file"), fileformats.HDF5), + (lf("filled_zarr_file"), fileformats.Zarr), ], ) def test_compression(test_file, file_format, compression, compression_opts, chunks): @@ -302,10 +302,10 @@ class TempSubClass(memh5.MemDiskGroup): @pytest.mark.parametrize( "test_file,file_format", [ - (lazy_fixture("h5_file"), fileformats.HDF5), - (lazy_fixture("zarr_file"), fileformats.Zarr), - (lazy_fixture("h5_file"), None), - (lazy_fixture("zarr_file"), None), + (lf("h5_file"), fileformats.HDF5), + (lf("zarr_file"), fileformats.Zarr), + (lf("h5_file"), None), + (lf("zarr_file"), None), ], ) def test_io(test_file, file_format): @@ -395,9 +395,9 @@ def zarrzip_basiccont_file(zarr_basiccont_file): @pytest.mark.parametrize( "test_file,file_format", [ - (lazy_fixture("h5_basiccont_file"), fileformats.HDF5), - (lazy_fixture("zarr_basiccont_file"), fileformats.Zarr), - (lazy_fixture("zarrzip_basiccont_file"), fileformats.Zarr), + (lf("h5_basiccont_file"), fileformats.HDF5), + (lf("zarr_basiccont_file"), fileformats.Zarr), + (lf("zarrzip_basiccont_file"), fileformats.Zarr), ], ) def test_access(test_file, file_format): @@ -420,8 +420,8 @@ def test_access(test_file, file_format): @pytest.mark.parametrize( "test_file,file_format", [ - (lazy_fixture("h5_basiccont_file"), fileformats.HDF5), - (lazy_fixture("zarr_basiccont_file"), fileformats.Zarr), + (lf("h5_basiccont_file"), fileformats.HDF5), + (lf("zarr_basiccont_file"), fileformats.Zarr), ], ) def test_history(test_file, file_format): @@ -459,8 +459,8 @@ def test_history(test_file, file_format): @pytest.mark.parametrize( "test_file,file_format", [ - (lazy_fixture("h5_file"), fileformats.HDF5), - (lazy_fixture("zarr_file"), fileformats.Zarr), + (lf("h5_file"), fileformats.HDF5), + (lf("zarr_file"), fileformats.Zarr), ], ) def test_to_from__file_unicode(test_file, file_format): @@ -519,8 +519,8 @@ def test_to_from__file_unicode(test_file, file_format): @pytest.mark.parametrize( "test_file,file_format", [ - (lazy_fixture("h5_file"), fileformats.HDF5), - (lazy_fixture("zarr_file"), fileformats.Zarr), + (lf("h5_file"), fileformats.HDF5), + (lf("zarr_file"), fileformats.Zarr), ], ) def test_failure(test_file, file_format): @@ -537,8 +537,8 @@ def test_failure(test_file, file_format): @pytest.mark.parametrize( "test_file,file_format", [ - (lazy_fixture("h5_file"), fileformats.HDF5), - (lazy_fixture("zarr_file"), fileformats.Zarr), + (lf("h5_file"), fileformats.HDF5), + (lf("zarr_file"), fileformats.Zarr), ], ) def test_to_from_hdf5(test_file, file_format): @@ -567,8 +567,8 @@ def test_to_from_hdf5(test_file, file_format): @pytest.mark.parametrize( "test_file,file_format", [ - (lazy_fixture("h5_file"), fileformats.HDF5), - (lazy_fixture("zarr_file"), fileformats.Zarr), + (lf("h5_file"), fileformats.HDF5), + (lf("zarr_file"), fileformats.Zarr), ], ) def test_json_failure(test_file, file_format): diff --git a/caput/tests/test_memh5_parallel.py b/caput/tests/test_memh5_parallel.py index 5d1667a3..4c0c975f 100644 --- a/caput/tests/test_memh5_parallel.py +++ b/caput/tests/test_memh5_parallel.py @@ -1,7 +1,7 @@ """Unit tests for the parallel features of the memh5 module.""" import pytest -from pytest_lazyfixture import lazy_fixture +from pytest_lazy_fixtures import lf import numpy as np import h5py import zarr @@ -62,9 +62,9 @@ def test_create_dataset(): @pytest.mark.parametrize( "test_file,file_open_function,file_format", [ - (lazy_fixture("h5_file_distributed"), h5py.File, fileformats.HDF5), + (lf("h5_file_distributed"), h5py.File, fileformats.HDF5), ( - lazy_fixture("zarr_file_distributed"), + lf("zarr_file_distributed"), zarr.open_group, fileformats.Zarr, ), @@ -173,9 +173,9 @@ def test_io( @pytest.mark.parametrize( "test_file,file_open_function,file_format", [ - (lazy_fixture("h5_file_distributed"), h5py.File, fileformats.HDF5), + (lf("h5_file_distributed"), h5py.File, fileformats.HDF5), ( - lazy_fixture("zarr_file_distributed"), + lf("zarr_file_distributed"), zarr.open_group, fileformats.Zarr, ), diff --git a/caput/tests/test_mpiarray.py b/caput/tests/test_mpiarray.py index 7e94da2a..2b582539 100644 --- a/caput/tests/test_mpiarray.py +++ b/caput/tests/test_mpiarray.py @@ -8,7 +8,7 @@ from typing import Union from packaging import version import pytest -from pytest_lazyfixture import lazy_fixture +from pytest_lazy_fixtures import lf import h5py import numpy as np import zarr @@ -126,9 +126,9 @@ def test_wrap(): @pytest.mark.parametrize( "filename, file_open_function, file_format", [ - (lazy_fixture("h5_file_distributed"), h5py.File, fileformats.HDF5), + (lf("h5_file_distributed"), h5py.File, fileformats.HDF5), ( - lazy_fixture("zarr_file_distributed"), + lf("zarr_file_distributed"), zarr.open_group, fileformats.Zarr, ), diff --git a/caput/tests/test_selection.py b/caput/tests/test_selection.py index 1d45d95a..859842c2 100644 --- a/caput/tests/test_selection.py +++ b/caput/tests/test_selection.py @@ -1,7 +1,7 @@ """Serial version of the selection tests.""" import pytest -from pytest_lazyfixture import lazy_fixture +from pytest_lazy_fixtures import lf import numpy as np from caput.memh5 import MemGroup @@ -40,8 +40,8 @@ def zarr_file_select(datasets, zarr_file): @pytest.mark.parametrize( "container_on_disk, file_format", [ - (lazy_fixture("h5_file_select"), fileformats.HDF5), - (lazy_fixture("zarr_file_select"), fileformats.Zarr), + (lf("h5_file_select"), fileformats.HDF5), + (lf("zarr_file_select"), fileformats.Zarr), ], ) def test_file_select(container_on_disk, file_format): @@ -57,9 +57,9 @@ def test_file_select(container_on_disk, file_format): @pytest.mark.parametrize( "container_on_disk, file_format", [ - (lazy_fixture("h5_file_select"), fileformats.HDF5), + (lf("h5_file_select"), fileformats.HDF5), pytest.param( - lazy_fixture("zarr_file_select"), + lf("zarr_file_select"), fileformats.Zarr, marks=pytest.mark.xfail(reason="Zarr doesn't support index selections."), ), diff --git a/caput/tests/test_selection_parallel.py b/caput/tests/test_selection_parallel.py index 1b1c925f..887c4688 100644 --- a/caput/tests/test_selection_parallel.py +++ b/caput/tests/test_selection_parallel.py @@ -6,7 +6,7 @@ from mpi4py import MPI import numpy as np import pytest -from pytest_lazyfixture import lazy_fixture +from pytest_lazy_fixtures import lf from caput import mpiutil, mpiarray, fileformats from caput.memh5 import MemGroup @@ -51,8 +51,8 @@ def xfail_zarr_listsel(request): @pytest.mark.parametrize( "file_name, file_format", [ - (lazy_fixture("h5_file"), fileformats.HDF5), - (lazy_fixture("zarr_file"), fileformats.Zarr), + (lf("h5_file"), fileformats.HDF5), + (lf("zarr_file"), fileformats.Zarr), ], ) @pytest.mark.parametrize("fsel", [slice(1, 8, 2), slice(5, 8, 2)])