Skip to content

Commit 096c043

Browse files
to squash personally: fix formatting
1 parent 8cd6d17 commit 096c043

File tree

1 file changed

+14
-20
lines changed

1 file changed

+14
-20
lines changed

src/_pytest/recwarn.py

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,11 @@ def warns(
142142
__tracebackhide__ = True
143143
if not args:
144144
if kwargs:
145-
msg = "Unexpected keyword arguments passed to pytest.warns: "
146-
msg += ", ".join(sorted(kwargs))
147-
msg += "\nUse context-manager form instead?"
148-
raise TypeError(msg)
145+
argnames = ", ".join(sorted(kwargs))
146+
raise TypeError(
147+
f"Unexpected keyword arguments passed to pytest.warns: {argnames}"
148+
"\nUse context-manager form instead?"
149+
)
149150
return WarningsChecker(expected_warning, match_expr=match, _ispytest=True)
150151
else:
151152
func = args[0]
@@ -191,7 +192,7 @@ def pop(self, cls: Type[Warning] = Warning) -> "warnings.WarningMessage":
191192
if issubclass(w.category, cls):
192193
return self._list.pop(i)
193194
__tracebackhide__ = True
194-
raise AssertionError("%r not found in warning list" % cls)
195+
raise AssertionError(f"{cls!r} not found in warning list")
195196

196197
def clear(self) -> None:
197198
"""Clear the list of recorded warnings."""
@@ -202,7 +203,7 @@ def clear(self) -> None:
202203
def __enter__(self) -> "WarningsRecorder": # type: ignore
203204
if self._entered:
204205
__tracebackhide__ = True
205-
raise RuntimeError("Cannot enter %r twice" % self)
206+
raise RuntimeError(f"Cannot enter {self!r} twice")
206207
_list = super().__enter__()
207208
# record=True means it's None.
208209
assert _list is not None
@@ -218,7 +219,7 @@ def __exit__(
218219
) -> None:
219220
if not self._entered:
220221
__tracebackhide__ = True
221-
raise RuntimeError("Cannot exit %r without entering first" % self)
222+
raise RuntimeError(f"Cannot exit {self!r} without entering first")
222223

223224
super().__exit__(exc_type, exc_val, exc_tb)
224225

@@ -278,10 +279,8 @@ def found_str():
278279
if not any(issubclass(r.category, self.expected_warning) for r in self):
279280
__tracebackhide__ = True
280281
fail(
281-
"DID NOT WARN. No warnings of type {expected} were emitted. "
282-
"The list of emitted warnings is: [{found}].".format(
283-
expected=self.expected_warning, found=found_str()
284-
)
282+
f"DID NOT WARN. No warnings of type {self.expected_warning} were emitted. \n"
283+
f"The list of emitted warnings is: [{found_str()}]."
285284
)
286285
elif self.match_expr is not None:
287286
for r in self:
@@ -290,13 +289,8 @@ def found_str():
290289
break
291290
else:
292291
fail(
293-
"DID NOT WARN. No warnings of type {expected} matching the"
294-
" regex was emitted.\n"
295-
"The regex is: {match!r}\n"
296-
"The list of emitted warnings"
297-
" is: [{found}].".format(
298-
expected=self.expected_warning,
299-
match=self.match_expr,
300-
found=found_str(),
301-
)
292+
f"""\
293+
DID NOT WARN. No warnings of type {self.expected_warning} matching the regex was emitted.
294+
The regex is: {self.match_expr!r}
295+
The list of emitted warnings is: [{found_str()}]"""
302296
)

0 commit comments

Comments
 (0)