66
77import warnings
88
9+ # Annoyingly, this import is *not* redundant, as pytest import fails without it.
10+ import iris_grib # noqa: F401
911from iris_grib .grib_phenom_translation ._gribcode import (
1012 GenericConcreteGRIBCode ,
1113 GRIBCode ,
1214)
13- import netCDF4 as nc
1415import numpy as np
1516import pytest
1617
1718import iris
1819from iris .cube import Cube
20+ from iris .fileformats .netcdf ._thread_safe_nc import DatasetWrapper as NcDataset
1921from iris .fileformats .pp import STASH
2022
2123
@@ -38,7 +40,7 @@ def _check_load_inner(self, iris_name, nc_name, value):
3840 # Save : NB can fail
3941 iris .save (cube , self .tmp_ncpath )
4042 # Reopen for updating with netcdf
41- ds = nc . Dataset (self .tmp_ncpath , "r+" )
43+ ds = NcDataset (self .tmp_ncpath , "r+" )
4244 # Add the test attribute content.
4345 ds .variables ["x" ].setncattr (nc_name , value )
4446 ds .close ()
@@ -75,10 +77,11 @@ def test_dual_names(self):
7577 # Test the highly unusual case where both names occur.
7678 result = self ._check_load (value = "xxx" )
7779 # Modify the file variable to have *both* attributes
78- with nc .Dataset (self .tmp_ncpath , "r+" ) as ds :
79- var = ds .variables ["x" ]
80- var .um_stash_source = "x1"
81- var .ukmo__um_stash_source = "x2"
80+ ds = NcDataset (self .tmp_ncpath , "r+" )
81+ var = ds .variables ["x" ]
82+ var .um_stash_source = "x1"
83+ var .ukmo__um_stash_source = "x2"
84+ ds .close ()
8285
8386 # When re-loaded, this should raise a warning.
8487 msg = "Multiple file attributes would set .*STASH"
0 commit comments