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 @@ -344,10 +344,10 @@ def found_str():
344
344
for w in self :
345
345
if not self .matches (w ):
346
346
warnings .warn_explicit (
347
- str ( w .message ) ,
348
- w . message . __class__ , # type: ignore[arg-type]
349
- w .filename ,
350
- w .lineno ,
347
+ message = w .message ,
348
+ category = w . category ,
349
+ filename = w .filename ,
350
+ lineno = w .lineno ,
351
351
module = w .__module__ ,
352
352
source = w .source ,
353
353
)
Original file line number Diff line number Diff line change @@ -550,3 +550,17 @@ def test_it():
550
550
result = pytester .runpytest_subprocess ()
551
551
assert result .ret == ExitCode .INTERRUPTED
552
552
result .assert_outcomes ()
553
+
554
+
555
+ def test_multiple_arg_custom_warning () -> None :
556
+ """Test for issue #11906."""
557
+
558
+ class CustomWarning (UserWarning ):
559
+ def __init__ (self , a , b ):
560
+ pass
561
+
562
+ with pytest .warns (CustomWarning ):
563
+ with pytest .raises (pytest .fail .Exception , match = "DID NOT WARN" ):
564
+ with pytest .warns (CustomWarning , match = "not gonna match" ):
565
+ a , b = 1 , 2
566
+ warnings .warn (CustomWarning (a , b ))
You can’t perform that action at this time.
0 commit comments