1
- import re
2
1
import warnings
3
2
from typing import Optional
4
3
@@ -263,16 +262,18 @@ def test_as_contextmanager(self) -> None:
263
262
with pytest .warns (RuntimeWarning ):
264
263
warnings .warn ("user" , UserWarning )
265
264
excinfo .match (
266
- r"DID NOT WARN. No warnings of type \(.+RuntimeWarning.+,\) was emitted. "
267
- r"The list of emitted warnings is: \[UserWarning\('user',?\)\]."
265
+ r"DID NOT WARN. No warnings of type \(.+RuntimeWarning.+,\) were emitted. "
266
+ r"The list of emitted warnings is: \[\n"
267
+ r" UserWarning\('user'\),\n"
268
+ r"\]."
268
269
)
269
270
270
271
with pytest .raises (pytest .fail .Exception ) as excinfo :
271
272
with pytest .warns (UserWarning ):
272
273
warnings .warn ("runtime" , RuntimeWarning )
273
274
excinfo .match (
274
275
r"DID NOT WARN. No warnings of type \(.+UserWarning.+,\) was emitted. "
275
- r"The list of emitted warnings is: \[RuntimeWarning\('runtime',?\)\]."
276
+ r"The list of emitted warnings is: \[\n RuntimeWarning\('runtime',?\),\n \]."
276
277
)
277
278
278
279
with pytest .raises (pytest .fail .Exception ) as excinfo :
@@ -289,18 +290,14 @@ def test_as_contextmanager(self) -> None:
289
290
warnings .warn ("runtime" , RuntimeWarning )
290
291
warnings .warn ("import" , ImportWarning )
291
292
292
- message_template = (
293
- "DID NOT WARN. No warnings of type {0} was emitted. "
294
- "The list of emitted warnings is: {1}."
295
- )
296
- excinfo .match (
297
- re .escape (
298
- message_template .format (
299
- warning_classes , [each .message for each in warninfo ]
300
- )
301
- )
293
+ messages = "" .join (f" { each .message !r} ,\n " for each in warninfo )
294
+ expected_str = (
295
+ f"DID NOT WARN. No warnings of type { warning_classes } was emitted. "
296
+ f"The list of emitted warnings is: [\n { messages } ]."
302
297
)
303
298
299
+ assert str (excinfo .value ) == expected_str
300
+
304
301
def test_record (self ) -> None :
305
302
with pytest .warns (UserWarning ) as record :
306
303
warnings .warn ("user" , UserWarning )
0 commit comments