diff --git a/pyiron_snippets/deprecate.py b/pyiron_snippets/deprecate.py index 05840f1..728b2f7 100644 --- a/pyiron_snippets/deprecate.py +++ b/pyiron_snippets/deprecate.py @@ -146,7 +146,8 @@ def decorated(*args, **kwargs): if kw in self.arguments: warnings.warn( message_format.format( - "{function.__module__}.{function.__name__}({kw}={kwargs[kw]})" + f"{function.__module__}.{function.__qualname__}" + f"({kw}={kwargs[kw]})" ), category=self.category, stacklevel=2, diff --git a/tests/unit/test_deprecate.py b/tests/unit/test_deprecate.py index 2455fde..dabe7d3 100644 --- a/tests/unit/test_deprecate.py +++ b/tests/unit/test_deprecate.py @@ -4,6 +4,15 @@ from pyiron_snippets.deprecate import deprecate, deprecate_soon +class ToGiveAQualname: + content = "this is the string" + + @staticmethod + @deprecate(bar=f"Instead of {content}, we want to see a string") + def foo(bar=None, baz=None): + pass + + class TestDeprecator(unittest.TestCase): def test_deprecate(self): """Function decorated with `deprecate` should raise a warning.""" @@ -125,6 +134,15 @@ def food(bar=None, baz=None): food(baz=True) self.assertEqual(len(w), 2, "Not all warnings preserved.") + def test_warning_reference(self): + with warnings.catch_warnings(record=True) as w: + ToGiveAQualname.foo(bar=True) + self.assertIn( + f"{ToGiveAQualname.foo.__module__}.{ToGiveAQualname.foo.__qualname__}", + str(w[0].message), + msg="Ensure full reference to function appears in warning.", + ) + if __name__ == "__main__": unittest.main()