Skip to content

Commit 497ffc5

Browse files
committed
bug fix
implement @bluetech changes implement code review changes
1 parent 5feabaa commit 497ffc5

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

changelog/11906.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix regression with :func:`pytest.warns` using custom warning subclasses which have more than one parameter in their `__init__`.

src/_pytest/recwarn.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -322,10 +322,10 @@ def found_str():
322322
for w in self:
323323
if not self.matches(w):
324324
warnings.warn_explicit(
325-
str(w.message),
326-
w.message.__class__, # type: ignore[arg-type]
327-
w.filename,
328-
w.lineno,
325+
message=w.message,
326+
category=w.category,
327+
filename=w.filename,
328+
lineno=w.lineno,
329329
module=w.__module__,
330330
source=w.source,
331331
)

testing/test_recwarn.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,8 @@ def test_catch_warning_within_raise(self) -> None:
480480
raise ValueError("some exception")
481481

482482
def test_multiple_arg_custom_warning(self) -> None:
483+
"""Test for issue #11906."""
484+
483485
class CustomWarning(UserWarning):
484486
def __init__(self, a, b):
485487
pass

0 commit comments

Comments
 (0)