Skip to content

Commit c5c0478

Browse files
committed
TST: only partially skip image tests when pytest-mpl is missing
1 parent 6e85995 commit c5c0478

2 files changed

Lines changed: 11 additions & 11 deletions

File tree

tests/conftest.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,10 @@ def pytest_configure(config):
1616
mpl.use("Agg")
1717
else: # pragma: no cover
1818
config.addinivalue_line(
19-
"markers", "mpl_image_compare: skip (missing requirement: pytest_mpl)"
19+
"markers", "mpl_image_compare: partial skip (missing requirement: pytest_mpl)"
2020
)
2121

2222

23-
def pytest_runtest_setup(item):
24-
if HAVE_PYTEST_MPL:
25-
return
26-
if any(item.iter_markers(name="mpl_image_compare")): # pragma: no cover
27-
pytest.skip("missing requirement: pytest_mpl")
28-
29-
3023
def pytest_report_header(config, start_path) -> list[str]:
3124
fs = runtime_feature_set()
3225
diagnostics = fs.diagnostics(features=["free-threading", "JIT"])

tests/test_deposit.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import gpgi
1212
from gpgi._lib import _deposit_ngp_2D
1313

14+
from importlib.util import find_spec
15+
HAVE_PYTEST_MPL = find_spec("pytest-mpl") is not None
1416

1517
@pytest.fixture()
1618
def sample_2D_dataset():
@@ -120,11 +122,12 @@ def fake_dep(*args, metadata=None, **kwargs):
120122
@pytest.mark.parametrize("method", ["ngp", "cic", "tsc"])
121123
@pytest.mark.mpl_image_compare
122124
def test_2D_deposit(sample_2D_dataset, method):
123-
from matplotlib.figure import Figure
124125

125126
ds = sample_2D_dataset
126127
particle_density = ds.deposit("mass", method=method)
127128

129+
if not HAVE_PYTEST_MPL: return
130+
from matplotlib.figure import Figure
128131
fig = Figure()
129132
ax = fig.add_subplot()
130133

@@ -178,6 +181,7 @@ def test_1D_deposit(method, grid_type):
178181
if method == "ngp":
179182
assert mass.sum() == ds.particles.count
180183

184+
if not HAVE_PYTEST_MPL: return
181185
fig = Figure()
182186
ax = fig.add_subplot()
183187
ax.set(xlabel="x", ylabel="particle mass", title=f"Deposition method '{method}'")
@@ -241,10 +245,9 @@ def test_3D_deposit(method, dtype):
241245
assert deposit_3D.shape == tuple(a - 2 for a in full_deposit_3D.shape)
242246

243247

248+
244249
@pytest.mark.mpl_image_compare
245250
def test_readme_example():
246-
from matplotlib.figure import Figure
247-
248251
nx = ny = 64
249252
nparticles = 600_000
250253

@@ -271,6 +274,10 @@ def test_readme_example():
271274

272275
particle_mass = ds.deposit("mass", method="nearest_grid_point")
273276

277+
if not HAVE_PYTEST_MPL: return
278+
from matplotlib.figure import Figure
279+
280+
274281
fig = Figure()
275282
ax = fig.add_subplot()
276283
ax.set(aspect=1, xlabel="x", ylabel="y")

0 commit comments

Comments
 (0)