From 5ddbeb55a7acb9dbe46e45a90026bb19aaf61a1d Mon Sep 17 00:00:00 2001 From: damonge Date: Fri, 22 Nov 2024 16:42:38 +0000 Subject: [PATCH] check for deprecationwarning --- pyccl/baryons/baccoemu_baryons.py | 10 +++++----- pyccl/tests/test_cclerror.py | 8 ++++++++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/pyccl/baryons/baccoemu_baryons.py b/pyccl/baryons/baccoemu_baryons.py index 53a643e8b..e83fea1dc 100644 --- a/pyccl/baryons/baccoemu_baryons.py +++ b/pyccl/baryons/baccoemu_baryons.py @@ -2,7 +2,6 @@ import numpy as np from copy import deepcopy -from warnings import warn from .. import Pk2D, CCLDeprecationWarning from . import Baryons @@ -216,8 +215,9 @@ class BaccoemuBaryons(BaryonsBaccoemu): def __init__(self, *args, **kwargs): """This throws a deprecation warning on initialization.""" - warn(f"Class {self.__class__.__name__} will be deprecated. " + - f"Please use {BaryonsBaccoemu.__name__} instead.", - CCLDeprecationWarning, stacklevel=2) + from .. import warnings + warnings.warn(f"Class {self.__class__.__name__} will be deprecated. " + + f"Please use {BaryonsBaccoemu.__name__} instead.", + CCLDeprecationWarning, stacklevel=2, + importance='low') super().__init__(*args, **kwargs) - pass diff --git a/pyccl/tests/test_cclerror.py b/pyccl/tests/test_cclerror.py index 31aa6ac23..0e1df7475 100644 --- a/pyccl/tests/test_cclerror.py +++ b/pyccl/tests/test_cclerror.py @@ -94,3 +94,11 @@ def test_ccl_warning_verbosity(): with warnings.catch_warnings(): warnings.simplefilter("error") pyccl.WeakLensingTracer(cosmo, dndz=(z, nz)) + + +def test_ccl_deprecation_warning(): + # Switch to high verbosity to catch it + pyccl.update_warning_verbosity("high") + with pytest.warns(pyccl.CCLDeprecationWarning): + pyccl.baryons.BaccoemuBaryons() + pyccl.update_warning_verbosity("low")