Skip to content

Commit

Permalink
to squash personally: fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
RonnyPfannschmidt committed Oct 2, 2021
1 parent 8cd6d17 commit 096c043
Showing 1 changed file with 14 additions and 20 deletions.
34 changes: 14 additions & 20 deletions src/_pytest/recwarn.py
Expand Up @@ -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]
Expand Down Expand Up @@ -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."""
Expand All @@ -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
Expand All @@ -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)

Expand Down Expand Up @@ -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:
Expand All @@ -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()}]"""
)

0 comments on commit 096c043

Please sign in to comment.