-
Notifications
You must be signed in to change notification settings - Fork 368
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
TST: Skip scipy tests if scipy isn't installed #2282
Conversation
from scipy.interpolate import NearestNDInterpolator | ||
from scipy.signal import convolve2d | ||
except ImportError: | ||
pytest.skip("scipy is required for contouring", allow_module_level=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think contour
itself does not need scipy
, but specifically test_contour_linear_ring
uses those two imported objects. So I suggest moving the imports within that test and putting the skip just there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. Moved that down into the test.
try: | ||
import scipy.spatial | ||
except ImportError: | ||
pytest.skip("scipy is required for image transforms", allow_module_level=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In here, everything except test_regridding_with_invalid_extent
will pass providing you have at least one of scipy
or pykdtree
installed. Is it worth modifying this to try both imports? Or is it too unlikely that a developer would have pykdtree
but not scipy
?
I am also unclear how to add appropriate skips to the parametrization of test_regridding_with_invalid_extent
if we did that...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, it is simple enough to do the nested try/except and put the skip only at the nested version. I also added a skip to the parameterization if scipy can't be imported there.
a709f0d
to
e5706ea
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I run without scipy
or pykdtree
, I get failures in test_examples.py
and test_imges.py
. That could arguably be out of scope of this PR though.
Good catch, I didn't realize I had pykdtree hanging around still. In fact, I get even more |
I think it's definitely helpful given that neither of these are considered required, so IMO we should be able to run the test suite successfully without them. |
I guess the alternative is to add one/both to the "test" optional dependencies. |
25ea7bb
to
a52198f
Compare
Alright, I refactored it a bit and tested this with the various combinations of pykdtree/scipy available/not available so that there are no errors. There are a few problems that were slightly annoying and made this maybe a little more verbose than ideal:
|
Significant changes and scope expansion since this approval
Seems to still be conflicts now? |
90dbe6c
to
7294ac8
Compare
import pytest | ||
|
||
|
||
try: | ||
import scipy # noqa: F401 | ||
except ImportError: | ||
pytest.skip("scipy is required for vector transforms", allow_module_level=True) | ||
|
||
|
||
import cartopy.crs as ccrs | ||
import cartopy.vector_transform as vec_trans |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import pytest | |
try: | |
import scipy # noqa: F401 | |
except ImportError: | |
pytest.skip("scipy is required for vector transforms", allow_module_level=True) | |
import cartopy.crs as ccrs | |
import cartopy.vector_transform as vec_trans | |
from cartopy.tests.conftest import requires_scipy | |
import cartopy.crs as ccrs | |
import cartopy.vector_transform as vec_trans | |
pytestmark = requires_scipy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one unfortunately doesn't work because import cartopy.vector_transform
raises an import error before the pytestmark takes effect.
7294ac8
to
d32f129
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for previously messed up review - I started adding comments a couple of weeks ago but then PRed that change instead. Then forgot I still had the comment here when I approved it. Can’t seem to delete the comment now either.
Anyway, I think this is good to go.
Needs a rebase. |
If a user doesn't have scipy or pykdtree installed on their system they can not import image transform modules, so we also need to skip these tests for them.
d32f129
to
8c308e8
Compare
Scipy isn't a required dependency, so skip the tests that require scipy if scipy isn't found.
pytest.importorskip
in the module-level imports caused flake8 warnings, so I decided to just try/except and skip instead which passes flake8 without requiring a bunch of extra ignores.closes #2275