@@ -145,15 +145,15 @@ def warns(
145145 You may also set the keyword argument ``keep_ignores`` to avoid catching warnings
146146 which were filtered out, in pytest configuration or otherwise::
147147
148- >>> warnings.simplefilter("ignore", category=FutureWarning )
148+ >>> warnings.simplefilter("ignore", category=UserWarning )
149149 >>> with pytest.warns(UserWarning, keep_ignores=True):
150150 ... warnings.warn("ignore this warning", UserWarning)
151151 Traceback (most recent call last):
152152 ...
153153 Failed: DID NOT WARN. No warnings of type ...UserWarning... were emitted...
154154
155155 >>> with pytest.warns(RuntimeWarning):
156- >>> warnings.simplefilter("ignore", category=FutureWarning )
156+ >>> warnings.simplefilter("ignore", category=UserWarning )
157157 >>> with pytest.warns(UserWarning, keep_ignores=True):
158158 ... warnings.warn("ignore this warning", UserWarning)
159159 warnings.warn("keep this warning", RuntimeWarning)
@@ -260,13 +260,15 @@ def __enter__(self) -> Self:
260260
261261 if self ._keep_ignores :
262262 for action , message , category , module , lineno in reversed (warnings .filters ):
263+ if isinstance (message , re .Pattern ):
264+ module = getattr (module , "pattern" , None ) # type: ignore[unreachable]
263265 if isinstance (module , re .Pattern ):
264266 module = getattr (module , "pattern" , None ) # type: ignore[unreachable]
265267 warnings .filterwarnings (
266268 action = "always" if action != "ignore" else "ignore" ,
267- message = message if isinstance ( message , str ) else "" ,
269+ message = message or "" ,
268270 category = category ,
269- module = module if isinstance ( module , str ) else "" ,
271+ module = module or "" ,
270272 lineno = lineno ,
271273 )
272274 else :
0 commit comments