diff --git a/changelog/8508.improvement.rst b/changelog/8508.improvement.rst index 36fb945829c..09b83613d69 100644 --- a/changelog/8508.improvement.rst +++ b/changelog/8508.improvement.rst @@ -1,2 +1,2 @@ Introduce multiline display for warning matching via :py:func:`pytest.warns` and -enhance match comparison for :py:func:`_pytest._code.ExceptionInfo.match` as returned by :py:func:`pytest.raises`. +enhance match comparison for :py:func:`pytest.ExceptionInfo.match` as returned by :py:func:`pytest.raises`. diff --git a/src/_pytest/recwarn.py b/src/_pytest/recwarn.py index 29b8318f7ac..adba0a84c42 100644 --- a/src/_pytest/recwarn.py +++ b/src/_pytest/recwarn.py @@ -279,7 +279,7 @@ def found_str(): if not any(issubclass(r.category, self.expected_warning) for r in self): __tracebackhide__ = True fail( - f"DID NOT WARN. No warnings of type {self.expected_warning} were emitted. \n" + f"DID NOT WARN. No warnings of type {self.expected_warning} were emitted.\n" f"The list of emitted warnings is: {found_str()}." ) elif self.match_expr is not None: diff --git a/testing/test_recwarn.py b/testing/test_recwarn.py index d8e9d9fcb32..78f27fa0ef6 100644 --- a/testing/test_recwarn.py +++ b/testing/test_recwarn.py @@ -262,7 +262,7 @@ def test_as_contextmanager(self) -> None: with pytest.warns(RuntimeWarning): warnings.warn("user", UserWarning) excinfo.match( - r"DID NOT WARN. No warnings of type \(.+RuntimeWarning.+,\) were emitted. \n" + r"DID NOT WARN. No warnings of type \(.+RuntimeWarning.+,\) were emitted.\n" r"The list of emitted warnings is: \[UserWarning\('user',?\)\]." ) @@ -270,7 +270,7 @@ def test_as_contextmanager(self) -> None: with pytest.warns(UserWarning): warnings.warn("runtime", RuntimeWarning) excinfo.match( - r"DID NOT WARN. No warnings of type \(.+UserWarning.+,\) were emitted. \n" + r"DID NOT WARN. No warnings of type \(.+UserWarning.+,\) were emitted.\n" r"The list of emitted warnings is: \[RuntimeWarning\('runtime',?\)]." ) @@ -278,7 +278,7 @@ def test_as_contextmanager(self) -> None: with pytest.warns(UserWarning): pass excinfo.match( - r"DID NOT WARN. No warnings of type \(.+UserWarning.+,\) were emitted. \n" + r"DID NOT WARN. No warnings of type \(.+UserWarning.+,\) were emitted.\n" r"The list of emitted warnings is: \[\]." ) @@ -290,7 +290,7 @@ def test_as_contextmanager(self) -> None: messages = [each.message for each in warninfo] expected_str = ( - f"DID NOT WARN. No warnings of type {warning_classes} were emitted. \n" + f"DID NOT WARN. No warnings of type {warning_classes} were emitted.\n" f"The list of emitted warnings is: {messages}." )