1
- import re
2
1
import warnings
3
2
from typing import Optional
4
3
@@ -253,15 +252,17 @@ def test_as_contextmanager(self) -> None:
253
252
warnings .warn ("user" , UserWarning )
254
253
excinfo .match (
255
254
r"DID NOT WARN. No warnings of type \(.+RuntimeWarning.+,\) was emitted. "
256
- r"The list of emitted warnings is: \[UserWarning\('user',?\)\]."
255
+ r"The list of emitted warnings is: \[\n"
256
+ r" UserWarning\('user'\),\n"
257
+ r"\]."
257
258
)
258
259
259
260
with pytest .raises (pytest .fail .Exception ) as excinfo :
260
261
with pytest .warns (UserWarning ):
261
262
warnings .warn ("runtime" , RuntimeWarning )
262
263
excinfo .match (
263
264
r"DID NOT WARN. No warnings of type \(.+UserWarning.+,\) was emitted. "
264
- r"The list of emitted warnings is: \[RuntimeWarning\('runtime',?\)\]."
265
+ r"The list of emitted warnings is: \[\n RuntimeWarning\('runtime',?\),\n \]."
265
266
)
266
267
267
268
with pytest .raises (pytest .fail .Exception ) as excinfo :
@@ -278,18 +279,14 @@ def test_as_contextmanager(self) -> None:
278
279
warnings .warn ("runtime" , RuntimeWarning )
279
280
warnings .warn ("import" , ImportWarning )
280
281
281
- message_template = (
282
- "DID NOT WARN. No warnings of type {0} was emitted. "
283
- "The list of emitted warnings is: {1}."
284
- )
285
- excinfo .match (
286
- re .escape (
287
- message_template .format (
288
- warning_classes , [each .message for each in warninfo ]
289
- )
290
- )
282
+ messages = "" .join (f" { each .message !r} ,\n " for each in warninfo )
283
+ expected_str = (
284
+ f"DID NOT WARN. No warnings of type { warning_classes } was emitted. "
285
+ f"The list of emitted warnings is: [\n { messages } ]."
291
286
)
292
287
288
+ assert str (excinfo .value ) == expected_str
289
+
293
290
def test_record (self ) -> None :
294
291
with pytest .warns (UserWarning ) as record :
295
292
warnings .warn ("user" , UserWarning )
0 commit comments