Skip to content

Commit d200598

Browse files
[pre-commit.ci] pre-commit autoupdate (#8547)
* [pre-commit.ci] pre-commit autoupdate * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Ran Benita <[email protected]>
1 parent 4b214a6 commit d200598

20 files changed

+30
-38
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ repos:
3434
- id: reorder-python-imports
3535
args: ['--application-directories=.:src', --py36-plus]
3636
- repo: https://github.com/asottile/pyupgrade
37-
rev: v2.11.0
37+
rev: v2.12.0
3838
hooks:
3939
- id: pyupgrade
4040
args: [--py36-plus]

src/_pytest/_code/code.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -968,7 +968,7 @@ def __str__(self) -> str:
968968
return io.getvalue().strip()
969969

970970
def __repr__(self) -> str:
971-
return "<{} instance at {:0x}>".format(self.__class__, id(self))
971+
return f"<{self.__class__} instance at {id(self):0x}>"
972972

973973
def toterminal(self, tw: TerminalWriter) -> None:
974974
raise NotImplementedError()

src/_pytest/_io/saferepr.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def _try_repr_or_str(obj: object) -> str:
1212
except (KeyboardInterrupt, SystemExit):
1313
raise
1414
except BaseException:
15-
return '{}("{}")'.format(type(obj).__name__, obj)
15+
return f'{type(obj).__name__}("{obj}")'
1616

1717

1818
def _format_repr_exception(exc: BaseException, obj: object) -> str:
@@ -21,7 +21,7 @@ def _format_repr_exception(exc: BaseException, obj: object) -> str:
2121
except (KeyboardInterrupt, SystemExit):
2222
raise
2323
except BaseException as exc:
24-
exc_info = "unpresentable exception ({})".format(_try_repr_or_str(exc))
24+
exc_info = f"unpresentable exception ({_try_repr_or_str(exc)})"
2525
return "<[{} raised in repr()] {} object at 0x{:x}>".format(
2626
exc_info, type(obj).__name__, id(obj)
2727
)

src/_pytest/compat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,4 +418,4 @@ def __get__(self, instance, owner=None):
418418
#
419419
# This also work for Enums (if you use `is` to compare) and Literals.
420420
def assert_never(value: "NoReturn") -> "NoReturn":
421-
assert False, "Unhandled value: {} ({})".format(value, type(value).__name__)
421+
assert False, f"Unhandled value: {value} ({type(value).__name__})"

src/_pytest/config/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ def import_plugin(self, modname: str, consider_entry_points: bool = False) -> No
721721
__import__(importspec)
722722
except ImportError as e:
723723
raise ImportError(
724-
'Error importing plugin "{}": {}'.format(modname, str(e.args[0]))
724+
f'Error importing plugin "{modname}": {e.args[0]}'
725725
).with_traceback(e.__traceback__) from e
726726

727727
except Skipped as e:

src/_pytest/fixtures.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ def formatrepr(self) -> "FixtureLookupErrorRepr":
859859
error_msg = "file %s, line %s: source code not available"
860860
addline(error_msg % (fspath, lineno + 1))
861861
else:
862-
addline("file {}, line {}".format(fspath, lineno + 1))
862+
addline(f"file {fspath}, line {lineno + 1}")
863863
for i, line in enumerate(lines):
864864
line = line.rstrip()
865865
addline(" " + line)
@@ -908,7 +908,7 @@ def toterminal(self, tw: TerminalWriter) -> None:
908908
lines = self.errorstring.split("\n")
909909
if lines:
910910
tw.line(
911-
"{} {}".format(FormattedExcinfo.fail_marker, lines[0].strip()),
911+
f"{FormattedExcinfo.fail_marker} {lines[0].strip()}",
912912
red=True,
913913
)
914914
for line in lines[1:]:
@@ -922,7 +922,7 @@ def toterminal(self, tw: TerminalWriter) -> None:
922922

923923
def fail_fixturefunc(fixturefunc, msg: str) -> "NoReturn":
924924
fs, lineno = getfslineno(fixturefunc)
925-
location = "{}:{}".format(fs, lineno + 1)
925+
location = f"{fs}:{lineno + 1}"
926926
source = _pytest._code.Source(fixturefunc)
927927
fail(msg + ":\n\n" + str(source.indent()) + "\n" + location, pytrace=False)
928928

src/_pytest/main.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ def wrap_session(
294294
except exit.Exception as exc:
295295
if exc.returncode is not None:
296296
session.exitstatus = exc.returncode
297-
sys.stderr.write("{}: {}\n".format(type(exc).__name__, exc))
297+
sys.stderr.write(f"{type(exc).__name__}: {exc}\n")
298298
else:
299299
if isinstance(excinfo.value, SystemExit):
300300
sys.stderr.write("mainloop: caught unexpected SystemExit!\n")
@@ -311,7 +311,7 @@ def wrap_session(
311311
except exit.Exception as exc:
312312
if exc.returncode is not None:
313313
session.exitstatus = exc.returncode
314-
sys.stderr.write("{}: {}\n".format(type(exc).__name__, exc))
314+
sys.stderr.write(f"{type(exc).__name__}: {exc}\n")
315315
config._ensure_unconfigure()
316316
return session.exitstatus
317317

@@ -718,7 +718,7 @@ def collect(self) -> Iterator[Union[nodes.Item, nodes.Collector]]:
718718
# If it's a directory argument, recurse and look for any Subpackages.
719719
# Let the Package collector deal with subnodes, don't collect here.
720720
if argpath.is_dir():
721-
assert not names, "invalid arg {!r}".format((argpath, names))
721+
assert not names, f"invalid arg {(argpath, names)!r}"
722722

723723
seen_dirs: Set[Path] = set()
724724
for direntry in visit(str(argpath), self._recurse):

src/_pytest/mark/expression.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def lex(self, input: str) -> Iterator[Token]:
103103
else:
104104
raise ParseError(
105105
pos + 1,
106-
'unexpected character "{}"'.format(input[pos]),
106+
f'unexpected character "{input[pos]}"',
107107
)
108108
yield Token(TokenType.EOF, "", pos)
109109

src/_pytest/mark/structures.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,7 @@ def param(
9999

100100
if id is not None:
101101
if not isinstance(id, str):
102-
raise TypeError(
103-
"Expected id to be a string, got {}: {!r}".format(type(id), id)
104-
)
102+
raise TypeError(f"Expected id to be a string, got {type(id)}: {id!r}")
105103
id = ascii_escaped(id)
106104
return cls(values, marks, id)
107105

src/_pytest/pastebin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def create_new_paste(contents: Union[str, bytes]) -> str:
8686
return "bad response: %s" % exc_info
8787
m = re.search(r'href="/raw/(\w+)"', response)
8888
if m:
89-
return "{}/show/{}".format(url, m.group(1))
89+
return f"{url}/show/{m.group(1)}"
9090
else:
9191
return "bad response: invalid format ('" + response + "')"
9292

src/_pytest/pathlib.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -500,9 +500,7 @@ def import_path(
500500
spec = importlib.util.spec_from_file_location(module_name, str(path))
501501

502502
if spec is None:
503-
raise ImportError(
504-
"Can't find module {} at location {}".format(module_name, str(path))
505-
)
503+
raise ImportError(f"Can't find module {module_name} at location {path}")
506504
mod = importlib.util.module_from_spec(spec)
507505
sys.modules[module_name] = mod
508506
spec.loader.exec_module(mod) # type: ignore[union-attr]

src/_pytest/pytester.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1865,7 +1865,7 @@ def _match_lines(
18651865
Match lines consecutively?
18661866
"""
18671867
if not isinstance(lines2, collections.abc.Sequence):
1868-
raise TypeError("invalid type for lines2: {}".format(type(lines2).__name__))
1868+
raise TypeError(f"invalid type for lines2: {type(lines2).__name__}")
18691869
lines2 = self._getlines(lines2)
18701870
lines1 = self.lines[:]
18711871
extralines = []

src/_pytest/python.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,7 +1400,7 @@ def idmaker(
14001400
# Suffix non-unique IDs to make them unique.
14011401
for index, test_id in enumerate(resolved_ids):
14021402
if test_id_counts[test_id] > 1:
1403-
resolved_ids[index] = "{}{}".format(test_id, test_id_suffixes[test_id])
1403+
resolved_ids[index] = f"{test_id}{test_id_suffixes[test_id]}"
14041404
test_id_suffixes[test_id] += 1
14051405

14061406
return resolved_ids
@@ -1449,7 +1449,7 @@ def write_item(item: nodes.Item) -> None:
14491449
tw.line()
14501450
tw.sep("-", f"fixtures used by {item.name}")
14511451
# TODO: Fix this type ignore.
1452-
tw.sep("-", "({})".format(get_best_relpath(item.function))) # type: ignore[attr-defined]
1452+
tw.sep("-", f"({get_best_relpath(item.function)})") # type: ignore[attr-defined]
14531453
# dict key not used in loop but needed for sorting.
14541454
for _, fixturedefs in sorted(info.name2fixturedefs.items()):
14551455
assert fixturedefs is not None

src/_pytest/python_api.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -733,9 +733,7 @@ def raises(
733733
else:
734734
func = args[0]
735735
if not callable(func):
736-
raise TypeError(
737-
"{!r} object (type: {}) must be callable".format(func, type(func))
738-
)
736+
raise TypeError(f"{func!r} object (type: {type(func)}) must be callable")
739737
try:
740738
func(*args[1:], **kwargs)
741739
except expected_exception as e:

src/_pytest/recwarn.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,7 @@ def warns(
149149
else:
150150
func = args[0]
151151
if not callable(func):
152-
raise TypeError(
153-
"{!r} object (type: {}) must be callable".format(func, type(func))
154-
)
152+
raise TypeError(f"{func!r} object (type: {type(func)}) must be callable")
155153
with WarningsChecker(expected_warning, _ispytest=True):
156154
return func(*args[1:], **kwargs)
157155

src/_pytest/setuponly.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def _show_fixture_action(fixturedef: FixtureDef[object], msg: str) -> None:
7979
tw.write(" (fixtures used: {})".format(", ".join(deps)))
8080

8181
if hasattr(fixturedef, "cached_param"):
82-
tw.write("[{}]".format(saferepr(fixturedef.cached_param, maxsize=42))) # type: ignore[attr-defined]
82+
tw.write(f"[{saferepr(fixturedef.cached_param, maxsize=42)}]") # type: ignore[attr-defined]
8383

8484
tw.flush()
8585

src/_pytest/terminal.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ def pytest_runtest_logfinish(self, nodeid: str) -> None:
588588
if self.verbosity <= 0 and self._show_progress_info:
589589
if self._show_progress_info == "count":
590590
num_tests = self._session.testscollected
591-
progress_length = len(" [{}/{}]".format(str(num_tests), str(num_tests)))
591+
progress_length = len(f" [{num_tests}/{num_tests}]")
592592
else:
593593
progress_length = len(" [100%]")
594594

@@ -610,7 +610,7 @@ def _get_progress_information_message(self) -> str:
610610
if self._show_progress_info == "count":
611611
if collected:
612612
progress = self._progress_nodeids_reported
613-
counter_format = "{{:{}d}}".format(len(str(collected)))
613+
counter_format = f"{{:{len(str(collected))}d}}"
614614
format_string = f" [{counter_format}/{{}}]"
615615
return format_string.format(len(progress), collected)
616616
return f" [ {collected} / {collected} ]"
@@ -704,7 +704,7 @@ def pytest_sessionstart(self, session: "Session") -> None:
704704
pypy_version_info = getattr(sys, "pypy_version_info", None)
705705
if pypy_version_info:
706706
verinfo = ".".join(map(str, pypy_version_info[:3]))
707-
msg += "[pypy-{}-{}]".format(verinfo, pypy_version_info[3])
707+
msg += f"[pypy-{verinfo}-{pypy_version_info[3]}]"
708708
msg += ", pytest-{}, py-{}, pluggy-{}".format(
709709
_pytest._version.version, py.__version__, pluggy.__version__
710710
)
@@ -1066,7 +1066,7 @@ def summary_stats(self) -> None:
10661066
msg = ", ".join(line_parts)
10671067

10681068
main_markup = {main_color: True}
1069-
duration = " in {}".format(format_session_duration(session_duration))
1069+
duration = f" in {format_session_duration(session_duration)}"
10701070
duration_with_markup = self._tw.markup(duration, **main_markup)
10711071
if display_sep:
10721072
fullwidth += len(duration_with_markup) - len(duration)

testing/acceptance_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def test_not_collectable_arguments(self, pytester: Pytester) -> None:
188188
result.stderr.fnmatch_lines(
189189
[
190190
f"ERROR: not found: {p2}",
191-
"(no name {!r} in any of [[][]])".format(str(p2)),
191+
f"(no name {str(p2)!r} in any of [[][]])",
192192
"",
193193
]
194194
)

testing/python/raises.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,15 @@ def test_no_raise_message(self) -> None:
144144
try:
145145
pytest.raises(ValueError, int, "0")
146146
except pytest.fail.Exception as e:
147-
assert e.msg == "DID NOT RAISE {}".format(repr(ValueError))
147+
assert e.msg == f"DID NOT RAISE {repr(ValueError)}"
148148
else:
149149
assert False, "Expected pytest.raises.Exception"
150150

151151
try:
152152
with pytest.raises(ValueError):
153153
pass
154154
except pytest.fail.Exception as e:
155-
assert e.msg == "DID NOT RAISE {}".format(repr(ValueError))
155+
assert e.msg == f"DID NOT RAISE {repr(ValueError)}"
156156
else:
157157
assert False, "Expected pytest.raises.Exception"
158158

testing/test_warnings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,7 @@ def test_it():
772772
# with stacklevel=2 the warning should originate from the above created test file
773773
result.stdout.fnmatch_lines_random(
774774
[
775-
"*{testfile}:3*".format(testfile=str(testfile)),
775+
f"*{testfile}:3*",
776776
"*Unknown pytest.mark.unknown*",
777777
]
778778
)

0 commit comments

Comments
 (0)