From 096c043d026b2c94eefa7efe0a13b7aa311a8c55 Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Sat, 2 Oct 2021 20:46:53 +0200 Subject: [PATCH] to squash personally: fix formatting --- src/_pytest/recwarn.py | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/src/_pytest/recwarn.py b/src/_pytest/recwarn.py index 14c70416e23..c7e3f82506a 100644 --- a/src/_pytest/recwarn.py +++ b/src/_pytest/recwarn.py @@ -142,10 +142,11 @@ def warns( __tracebackhide__ = True if not args: if kwargs: - msg = "Unexpected keyword arguments passed to pytest.warns: " - msg += ", ".join(sorted(kwargs)) - msg += "\nUse context-manager form instead?" - raise TypeError(msg) + argnames = ", ".join(sorted(kwargs)) + raise TypeError( + f"Unexpected keyword arguments passed to pytest.warns: {argnames}" + "\nUse context-manager form instead?" + ) return WarningsChecker(expected_warning, match_expr=match, _ispytest=True) else: func = args[0] @@ -191,7 +192,7 @@ def pop(self, cls: Type[Warning] = Warning) -> "warnings.WarningMessage": if issubclass(w.category, cls): return self._list.pop(i) __tracebackhide__ = True - raise AssertionError("%r not found in warning list" % cls) + raise AssertionError(f"{cls!r} not found in warning list") def clear(self) -> None: """Clear the list of recorded warnings.""" @@ -202,7 +203,7 @@ def clear(self) -> None: def __enter__(self) -> "WarningsRecorder": # type: ignore if self._entered: __tracebackhide__ = True - raise RuntimeError("Cannot enter %r twice" % self) + raise RuntimeError(f"Cannot enter {self!r} twice") _list = super().__enter__() # record=True means it's None. assert _list is not None @@ -218,7 +219,7 @@ def __exit__( ) -> None: if not self._entered: __tracebackhide__ = True - raise RuntimeError("Cannot exit %r without entering first" % self) + raise RuntimeError(f"Cannot exit {self!r} without entering first") super().__exit__(exc_type, exc_val, exc_tb) @@ -278,10 +279,8 @@ def found_str(): if not any(issubclass(r.category, self.expected_warning) for r in self): __tracebackhide__ = True fail( - "DID NOT WARN. No warnings of type {expected} were emitted. " - "The list of emitted warnings is: [{found}].".format( - expected=self.expected_warning, found=found_str() - ) + 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: for r in self: @@ -290,13 +289,8 @@ def found_str(): break else: fail( - "DID NOT WARN. No warnings of type {expected} matching the" - " regex was emitted.\n" - "The regex is: {match!r}\n" - "The list of emitted warnings" - " is: [{found}].".format( - expected=self.expected_warning, - match=self.match_expr, - found=found_str(), - ) + f"""\ +DID NOT WARN. No warnings of type {self.expected_warning} matching the regex was emitted. +The regex is: {self.match_expr!r} +The list of emitted warnings is: [{found_str()}]""" )