From 4e218ac53256eea11d3fecba177410340588747d Mon Sep 17 00:00:00 2001 From: "P. L. Lim" <2090236+pllim@users.noreply.github.com> Date: Mon, 8 Jan 2024 14:18:47 -0500 Subject: [PATCH] TST: Handle second warning in test_all_nan_uncert_subset because pytest 8 will turn it into exception but it is hidden in older pytest. --- .../plugins/model_fitting/tests/test_plugin.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/jdaviz/configs/default/plugins/model_fitting/tests/test_plugin.py b/jdaviz/configs/default/plugins/model_fitting/tests/test_plugin.py index 4763d76549..174de9f23b 100644 --- a/jdaviz/configs/default/plugins/model_fitting/tests/test_plugin.py +++ b/jdaviz/configs/default/plugins/model_fitting/tests/test_plugin.py @@ -4,12 +4,14 @@ """ import warnings import pytest +from contextlib import nullcontext import numpy as np from numpy.testing import assert_allclose from astropy.nddata import StdDevUncertainty from astropy.utils.exceptions import AstropyUserWarning +from astropy.utils.introspection import minversion import astropy.units as u from glue.core.roi import CircularROI, XRangeROI @@ -18,6 +20,8 @@ from jdaviz.configs.cubeviz.plugins.tests.test_parsers import ASTROPY_LT_5_3 from jdaviz.configs.default.plugins.model_fitting.initializers import MODELS +PYTEST_LT_8_0 = not minversion(pytest, "8.0.dev") + def test_default_model_labels(specviz_helper, spectrum1d): specviz_helper.load_data(spectrum1d) @@ -427,7 +431,13 @@ def test_all_nan_uncert_subset(specviz_helper): plugin = specviz_helper.plugins['Model Fitting'] plugin.create_model_component('Linear1D') - with pytest.warns(AstropyUserWarning, match='Model is linear in parameters'): + if PYTEST_LT_8_0: + ctx = nullcontext() + else: + ctx = pytest.warns( + AstropyUserWarning, match="Non-Finite input data has been removed by the fitter") + + with pytest.warns(AstropyUserWarning, match='Model is linear in parameters'), ctx: plugin.calculate_fit() # check that slope and intercept are fit correctly to just the first 2