File tree Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -146,7 +146,8 @@ def decorated(*args, **kwargs):
146146 if kw in self .arguments :
147147 warnings .warn (
148148 message_format .format (
149- "{function.__module__}.{function.__name__}({kw}={kwargs[kw]})"
149+ f"{ function .__module__ } .{ function .__qualname__ } "
150+ f"({ kw } ={ kwargs [kw ]} )"
150151 ),
151152 category = self .category ,
152153 stacklevel = 2 ,
Original file line number Diff line number Diff line change 44from pyiron_snippets .deprecate import deprecate , deprecate_soon
55
66
7+ class ToGiveAQualname :
8+ content = "this is the string"
9+
10+ @staticmethod
11+ @deprecate (bar = f"Instead of { content } , we want to see a string" )
12+ def foo (bar = None , baz = None ):
13+ pass
14+
15+
716class TestDeprecator (unittest .TestCase ):
817 def test_deprecate (self ):
918 """Function decorated with `deprecate` should raise a warning."""
@@ -125,6 +134,15 @@ def food(bar=None, baz=None):
125134 food (baz = True )
126135 self .assertEqual (len (w ), 2 , "Not all warnings preserved." )
127136
137+ def test_warning_reference (self ):
138+ with warnings .catch_warnings (record = True ) as w :
139+ ToGiveAQualname .foo (bar = True )
140+ self .assertIn (
141+ f"{ ToGiveAQualname .foo .__module__ } .{ ToGiveAQualname .foo .__qualname__ } " ,
142+ str (w [0 ].message ),
143+ msg = "Ensure full reference to function appears in warning." ,
144+ )
145+
128146
129147if __name__ == "__main__" :
130148 unittest .main ()
You can’t perform that action at this time.
0 commit comments