Skip to content

Commit 5d02df3

Browse files
authored
Merge pull request astropy#3614 from bsipocz/MAINT_fix_pytest_91
MAINT: fixing pytest9.1 incompatibilities
2 parents 5ee0d2c + 8a409e0 commit 5d02df3

7 files changed

Lines changed: 43 additions & 31 deletions

File tree

astroquery/besancon/tests/test_besancon.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ def data_path(filename):
3535

3636

3737
@pytest.mark.parametrize(('filename', 'length', 'ncols', 'd1', 'mv1'),
38-
zip(DATA_FILES, (13, 6), (18, 24), (0.091, 0.111),
39-
(10.20, 9.70)))
38+
list(zip(DATA_FILES, (13, 6), (18, 24), (0.091, 0.111),
39+
(10.20, 9.70))))
4040
def test_reader(filename, length, ncols, d1, mv1):
4141
besancon_model = data_path(filename)
4242
with open(besancon_model, 'r') as f:

astroquery/conftest.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Licensed under a 3-clause BSD style license - see LICENSE.rst
2+
3+
# Keep the project level fixtures in this file, keeping them in root level
4+
# conftest causes issues with pytest 9.1+
5+
6+
import os
7+
from pathlib import Path
8+
9+
import pytest
10+
11+
12+
@pytest.fixture(scope='function')
13+
def tmp_cwd(tmp_path):
14+
"""Perform test in a pristine temporary working directory."""
15+
old_dir = Path.cwd()
16+
os.chdir(tmp_path)
17+
try:
18+
yield tmp_path
19+
finally:
20+
os.chdir(old_dir)

astroquery/esasky/tests/test_esasky_remote.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,12 @@ def test_esasky_query_ids_spectra(self):
6868
assert "1342246640" in result["HERSCHEL"].columns["observation_id"]
6969

7070
@pytest.mark.parametrize("mission, obsid",
71-
zip(["SUZAKU", "ISO-IR", "Chandra", "XMM-OM-OPTICAL",
72-
"XMM", "XMM-OM-UV", "HST-IR", "Herschel",
73-
"Spitzer", "HST-UV", "HST-OPTICAL", "INTEGRAL"],
74-
["100001010", "01500403", "21171", "0852000101",
75-
"0851180201", "0851180201", "n3tr01c3q", "1342247257",
76-
"30002561-25100", "hst_07553_3h_wfpc2_f160bw_pc", "ocli05leq", "88600210001"]))
71+
list(zip(["SUZAKU", "ISO-IR", "Chandra", "XMM-OM-OPTICAL",
72+
"XMM", "XMM-OM-UV", "HST-IR", "Herschel",
73+
"Spitzer", "HST-UV", "HST-OPTICAL", "INTEGRAL"],
74+
["100001010", "01500403", "21171", "0852000101",
75+
"0851180201", "0851180201", "n3tr01c3q", "1342247257",
76+
"30002561-25100", "hst_07553_3h_wfpc2_f160bw_pc", "ocli05leq", "88600210001"])))
7777
def test_esasky_get_images_obs_id(self, tmp_path, mission, obsid):
7878
result = ESASky.get_images(observation_ids=obsid,
7979
missions=mission, download_dir=tmp_path)
@@ -89,10 +89,10 @@ def test_esasky_get_images_obs_id(self, tmp_path, mission, obsid):
8989
hdu_list.close()
9090

9191
@pytest.mark.parametrize("mission, observation_id",
92-
zip(["ISO-IR", "Chandra", "IUE", "XMM-NEWTON",
93-
"HST-IR", "Herschel", "HST-UV", "HST-OPTICAL"],
94-
["02101201", "1005", "LWR13178", "0001730201",
95-
"ibh706cqq", "1342253595", "z1ax0102t", "oeik2s020"]))
92+
list(zip(["ISO-IR", "Chandra", "IUE", "XMM-NEWTON",
93+
"HST-IR", "Herschel", "HST-UV", "HST-OPTICAL"],
94+
["02101201", "1005", "LWR13178", "0001730201",
95+
"ibh706cqq", "1342253595", "z1ax0102t", "oeik2s020"])))
9696
def test_esasky_get_spectra_obs_id(self, tmp_path, mission, observation_id):
9797
result = ESASky.get_spectra(observation_ids=observation_id,
9898
missions=mission, download_dir=tmp_path)
@@ -135,8 +135,9 @@ def test_esasky_get_images_for_erosita(self, tmp_path):
135135

136136
@pytest.mark.bigdata
137137
@pytest.mark.parametrize('mission, position',
138-
zip(['JWST-MID-IR', 'JWST-NEAR-IR'],
139-
['340.50123388127435 -69.17904779241904', '225.6864099965157 -3.0315781490149467']))
138+
list(zip(['JWST-MID-IR', 'JWST-NEAR-IR'],
139+
['340.50123388127435 -69.17904779241904',
140+
'225.6864099965157 -3.0315781490149467'])))
140141
def test_esasky_get_images_jwst(self, tmp_path, mission, position):
141142
result = ESASky.get_images(position=position, missions=mission, download_dir=tmp_path)
142143
assert tmp_path.stat().st_size

astroquery/linelists/cdms/tests/test_cdms_remote.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ def test_remote_all_species():
238238
class TestRegressionAllCats:
239239
species_table = CDMS.get_species_table(write_new_species_cache=False)
240240

241-
@pytest.mark.parametrize('row', species_table)
241+
@pytest.mark.parametrize('row', list(species_table))
242242
def test_regression_allcats(self, row):
243243
"""
244244
Expensive test - try all the molecules

astroquery/linelists/jplspec/tests/test_jplspec_remote.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ class TestRegressionAllMolecules:
239239
"""Test that we can get each molecule in JPL database"""
240240
species_table = JPLSpec.get_species_table()
241241

242-
@pytest.mark.parametrize('row', species_table)
242+
@pytest.mark.parametrize('row', list(species_table))
243243
def test_regression_all_molecules(self, row):
244244
"""
245245
Expensive test - try all the molecules
@@ -254,5 +254,5 @@ def test_regression_all_molecules(self, row):
254254
# N2O = 44009 is just not there
255255
pytest.skip("Skipping O2 due to masked QNs")
256256
tbl = JPLSpec.get_molecule(mol_id)
257-
assert isinstance(tbl, Table)
257+
assert isinstance(tbl, (Table,))
258258
assert len(tbl) > 0

astroquery/skyview/tests/test_skyview_remote.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def setup_class(cls):
3636

3737
@pytest.mark.parametrize(('survey',
3838
'survey_data'),
39-
zip(survey_dict.keys(), survey_dict.values()))
39+
list(zip(survey_dict.keys(), survey_dict.values())))
4040
def test_survey(self, survey, survey_data):
4141
# The print should help discover changes
4242
print("Survey: {0} \n Canned reference return: {1} \n"

conftest.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# Licensed under a 3-clause BSD style license - see LICENSE.rst
22

3-
import os
4-
from pathlib import Path
3+
# Keep basic config here, so both tox and directly run pytest works as expected.
4+
# Keep the fixtures one layer down for global fixtures and more layer down
5+
# for more specific scopes.
6+
57
import sys
68

79
from astropy.utils import minversion
@@ -59,17 +61,6 @@ def pytest_addoption(parser):
5961
)
6062

6163

62-
@pytest.fixture(scope='function')
63-
def tmp_cwd(tmp_path):
64-
"""Perform test in a pristine temporary working directory."""
65-
old_dir = Path.cwd()
66-
os.chdir(tmp_path)
67-
try:
68-
yield tmp_path
69-
finally:
70-
os.chdir(old_dir)
71-
72-
7364
def pytest_runtestloop(session):
7465
if sys.platform == 'win32':
7566
session.add_marker(pytest.mark.filterwarnings(

0 commit comments

Comments
 (0)