@@ -142,10 +142,11 @@ def warns(
142
142
__tracebackhide__ = True
143
143
if not args :
144
144
if kwargs :
145
- msg = "Unexpected keyword arguments passed to pytest.warns: "
146
- msg += ", " .join (sorted (kwargs ))
147
- msg += "\n Use context-manager form instead?"
148
- raise TypeError (msg )
145
+ argnames = ", " .join (sorted (kwargs ))
146
+ raise TypeError (
147
+ f"Unexpected keyword arguments passed to pytest.warns: { argnames } "
148
+ "\n Use context-manager form instead?"
149
+ )
149
150
return WarningsChecker (expected_warning , match_expr = match , _ispytest = True )
150
151
else :
151
152
func = args [0 ]
@@ -191,7 +192,7 @@ def pop(self, cls: Type[Warning] = Warning) -> "warnings.WarningMessage":
191
192
if issubclass (w .category , cls ):
192
193
return self ._list .pop (i )
193
194
__tracebackhide__ = True
194
- raise AssertionError ("%r not found in warning list" % cls )
195
+ raise AssertionError (f" { cls !r } not found in warning list" )
195
196
196
197
def clear (self ) -> None :
197
198
"""Clear the list of recorded warnings."""
@@ -202,7 +203,7 @@ def clear(self) -> None:
202
203
def __enter__ (self ) -> "WarningsRecorder" : # type: ignore
203
204
if self ._entered :
204
205
__tracebackhide__ = True
205
- raise RuntimeError ("Cannot enter %r twice" % self )
206
+ raise RuntimeError (f "Cannot enter { self !r } twice" )
206
207
_list = super ().__enter__ ()
207
208
# record=True means it's None.
208
209
assert _list is not None
@@ -218,7 +219,7 @@ def __exit__(
218
219
) -> None :
219
220
if not self ._entered :
220
221
__tracebackhide__ = True
221
- raise RuntimeError ("Cannot exit %r without entering first" % self )
222
+ raise RuntimeError (f "Cannot exit { self !r } without entering first" )
222
223
223
224
super ().__exit__ (exc_type , exc_val , exc_tb )
224
225
@@ -278,10 +279,8 @@ def found_str():
278
279
if not any (issubclass (r .category , self .expected_warning ) for r in self ):
279
280
__tracebackhide__ = True
280
281
fail (
281
- "DID NOT WARN. No warnings of type {expected} were emitted. "
282
- "The list of emitted warnings is: [{found}]." .format (
283
- expected = self .expected_warning , found = found_str ()
284
- )
282
+ f"DID NOT WARN. No warnings of type { self .expected_warning } were emitted. \n "
283
+ f"The list of emitted warnings is: [{ found_str ()} ]."
285
284
)
286
285
elif self .match_expr is not None :
287
286
for r in self :
@@ -290,13 +289,8 @@ def found_str():
290
289
break
291
290
else :
292
291
fail (
293
- "DID NOT WARN. No warnings of type {expected} matching the"
294
- " regex was emitted.\n "
295
- "The regex is: {match!r}\n "
296
- "The list of emitted warnings"
297
- " is: [{found}]." .format (
298
- expected = self .expected_warning ,
299
- match = self .match_expr ,
300
- found = found_str (),
301
- )
292
+ f"""\
293
+ DID NOT WARN. No warnings of type { self .expected_warning } matching the regex was emitted.
294
+ The regex is: { self .match_expr !r}
295
+ The list of emitted warnings is: [{ found_str ()} ]"""
302
296
)
0 commit comments