1
- import re
2
1
import warnings
3
2
from typing import Optional
4
3
@@ -251,23 +250,25 @@ def test_as_contextmanager(self) -> None:
251
250
with pytest .raises (pytest .fail .Exception ) as excinfo :
252
251
with pytest .warns (RuntimeWarning ):
253
252
warnings .warn ("user" , UserWarning )
254
- excinfo .match (
253
+ assert 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
- excinfo .match (
263
+ assert 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 :
268
269
with pytest .warns (UserWarning ):
269
270
pass
270
- excinfo .match (
271
+ assert excinfo .match (
271
272
r"DID NOT WARN. No warnings of type \(.+UserWarning.+,\) was emitted. "
272
273
r"The list of emitted warnings is: \[\]."
273
274
)
@@ -280,14 +281,11 @@ def test_as_contextmanager(self) -> None:
280
281
281
282
message_template = (
282
283
"DID NOT WARN. No warnings of type {0} was emitted. "
283
- "The list of emitted warnings is: {1}."
284
+ "The list of emitted warnings is: [ \n {1}] ."
284
285
)
285
- excinfo .match (
286
- re .escape (
287
- message_template .format (
288
- warning_classes , [each .message for each in warninfo ]
289
- )
290
- )
286
+
287
+ assert str (excinfo .value ) == message_template .format (
288
+ warning_classes , "" .join (f" { each .message !r} ,\n " for each in warninfo )
291
289
)
292
290
293
291
def test_record (self ) -> None :
0 commit comments