Skip to content

Commit d7aba96

Browse files
authored
Merge pull request #3039 from bsipocz/BUG_handling_optional_regions
BUG: better handling the optional dependency required for functionality
2 parents 2f2a643 + a682a6a commit d7aba96

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

astroquery/alma/core.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ def get_enhanced_table(result):
218218
print(
219219
"Could not import astropy-regions, which is a requirement for get_enhanced_table function in alma."
220220
"Please refer to http://astropy-regions.readthedocs.io/en/latest/installation.html for how to install it.")
221+
raise
221222

222223
def _parse_stcs_string(input):
223224
csys = 'icrs'

astroquery/alma/tests/test_alma_remote.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@
1616
from astroquery.exceptions import CorruptDataWarning
1717
from astroquery.alma import Alma, get_enhanced_table
1818

19+
try:
20+
import regions
21+
22+
HAS_REGIONS = True
23+
except ImportError:
24+
HAS_REGIONS = False
25+
1926
# ALMA tests involving staging take too long, leading to travis timeouts
2027
# TODO: make this a configuration item
2128
SKIP_SLOW = True
@@ -62,11 +69,10 @@ def test_public(self, alma):
6269
for row in results:
6370
assert row['data_rights'] == 'Proprietary'
6471

72+
@pytest.mark.skipif(not HAS_REGIONS, reason="regions is required")
6573
@pytest.mark.filterwarnings(
6674
"ignore::astropy.utils.exceptions.AstropyUserWarning")
6775
def test_s_region(self, alma):
68-
pytest.importorskip('regions')
69-
import regions # to silence checkstyle
7076
alma.help_tap()
7177
result = alma.query_tap("select top 3 s_region from ivoa.obscore")
7278
enhanced_result = get_enhanced_table(result)
@@ -75,6 +81,7 @@ def test_s_region(self, alma):
7581
regions.PolygonSkyRegion,
7682
regions.CompoundSkyRegion))
7783

84+
@pytest.mark.skipif(not HAS_REGIONS, reason="regions is required")
7885
@pytest.mark.filterwarnings(
7986
"ignore::astropy.utils.exceptions.AstropyUserWarning")
8087
def test_SgrAstar(self, tmp_path, alma):

0 commit comments

Comments
 (0)