File tree 3 files changed +19
-4
lines changed
3 files changed +19
-4
lines changed Original file line number Diff line number Diff line change
1
+ Fix regression with :func: `pytest.warns ` using custom warning subclasses which have more than one parameter in their `__init__ `.
Original file line number Diff line number Diff line change @@ -334,10 +334,10 @@ def found_str() -> str:
334
334
for w in self :
335
335
if not self .matches (w ):
336
336
warnings .warn_explicit (
337
- str ( w .message ) ,
338
- w . message . __class__ , # type: ignore[arg-type]
339
- w .filename ,
340
- w .lineno ,
337
+ message = w .message ,
338
+ category = w . category ,
339
+ filename = w .filename ,
340
+ lineno = w .lineno ,
341
341
module = w .__module__ ,
342
342
source = w .source ,
343
343
)
Original file line number Diff line number Diff line change @@ -581,3 +581,17 @@ def test_raise_type_error_on_invalid_warning_message_cpython() -> None:
581
581
with warnings .catch_warnings ():
582
582
warnings .filterwarnings ("ignore" , "test" )
583
583
warnings .warn (1 ) # type: ignore
584
+
585
+
586
+ def test_multiple_arg_custom_warning () -> None :
587
+ """Test for issue #11906."""
588
+
589
+ class CustomWarning (UserWarning ):
590
+ def __init__ (self , a , b ):
591
+ pass
592
+
593
+ with pytest .warns (CustomWarning ):
594
+ with pytest .raises (pytest .fail .Exception , match = "DID NOT WARN" ):
595
+ with pytest .warns (CustomWarning , match = "not gonna match" ):
596
+ a , b = 1 , 2
597
+ warnings .warn (CustomWarning (a , b ))
You can’t perform that action at this time.
0 commit comments