Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pyiron_snippets/deprecate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
18 changes: 18 additions & 0 deletions tests/unit/test_deprecate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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()
Loading