Skip to content

Commit 7c576cd

Browse files
Fix setUp variable unittest scoping in test_RegridOperator
1 parent 55b1ca3 commit 7c576cd

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

cf/test/test_RegridOperator.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import datetime
22
import faulthandler
3+
from importlib.util import find_spec
34
import unittest
45

56
faulthandler.enable() # to debug seg faults and timeouts
@@ -10,26 +11,18 @@
1011
# ESMF renamed its Python module to `esmpy` at ESMF version 8.4.0. Allow
1112
# either for now for backwards compatibility.
1213
esmpy_imported = False
13-
try:
14-
import esmpy
15-
14+
# Note: here only need esmpy for cf under-the-hood code, not in test
15+
# directly, so no need to actually import esmpy, just test it is there.
16+
if find_spec("esmpy") or find_spec("ESMF"):
1617
esmpy_imported = True
17-
except ImportError:
18-
try:
19-
# Take the new name to use in preference to the old one.
20-
import ESMF as esmpy
21-
22-
esmpy_imported = True
23-
except ImportError:
24-
pass
2518

2619

2720
class RegridOperatorTest(unittest.TestCase):
2821

2922
def setUp(self):
3023
src = cf.example_field(0)
3124
dst = cf.example_field(1)
32-
r = src.regrids(dst, "linear", return_operator=True)
25+
self.r = src.regrids(dst, "linear", return_operator=True)
3326

3427
@unittest.skipUnless(esmpy_imported, "Requires esmpy/ESMF package.")
3528
def test_RegridOperator_attributes(self):

0 commit comments

Comments
 (0)