@@ -135,8 +135,9 @@ def warns( # noqa: F811
135
135
>>> with pytest.warns(UserWarning, match=r'must be \d+$'):
136
136
... warnings.warn("value must be 42", UserWarning)
137
137
138
- >>> with pytest.warns(UserWarning, match=r'must be \d+$'):
139
- ... warnings.warn("this is not here", UserWarning)
138
+ >>> with pytest.warns(UserWarning): # catch re-emitted warning
139
+ ... with pytest.warns(UserWarning, match=r'must be \d+$'):
140
+ ... warnings.warn("this is not here", UserWarning)
140
141
Traceback (most recent call last):
141
142
...
142
143
Failed: DID NOT WARN. No warnings of type ...UserWarning... were emitted...
@@ -281,7 +282,8 @@ def __init__(
281
282
self .expected_warning = expected_warning_tup
282
283
self .match_expr = match_expr
283
284
284
- def matches (self , warning ) -> bool :
285
+ def matches (self , warning : warnings .WarningMessage ) -> bool :
286
+ assert self .expected_warning is not None
285
287
return issubclass (warning .category , self .expected_warning ) and (
286
288
self .match_expr is None or re .search (self .match_expr , str (warning .message ))
287
289
)
@@ -326,7 +328,7 @@ def found_str():
326
328
if not self .matches (w ):
327
329
warnings .warn_explicit (
328
330
str (w .message ),
329
- w .message .__class__ ,
331
+ w .message .__class__ , # type: ignore
330
332
w .filename ,
331
333
w .lineno ,
332
334
module = w .__module__ ,
0 commit comments