Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
minimum_pre_commit_version: "4.4.0"
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.14.14"
rev: "v0.15.4"
hooks:
- id: ruff-check
args: ["--fix"]
Expand Down Expand Up @@ -67,7 +67,7 @@ repos:
- exceptiongroup>=1.0.0rc8
# Manual because passing pyright is a work in progress.
stages: [manual]
- repo: https://github.com/tox-dev/pyproject-fmt
- repo: https://github.com/pytest-dev/pyproject-fmt
rev: "v2.12.1"
hooks:
- id: pyproject-fmt
Expand Down
21 changes: 11 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ lint.ignore = [
"PLW2901", # for loop variable overwritten by assignment target
# ruff ignore
"RUF012", # Mutable class attributes should be annotated with `typing.ClassVar`
"RUF061", # Use context-manager form of `pytest.raises()`
]
lint.per-file-ignores."src/_pytest/_py/**/*.py" = [
"B",
Expand All @@ -169,6 +170,7 @@ lint.per-file-ignores."src/_pytest/_py/**/*.py" = [
lint.per-file-ignores."src/_pytest/_version.py" = [
"I001",
]
lint.per-file-ignores."testing/**/*.py" = [ "RUF060" ]
# can't be disabled on a line-by-line basis in file
lint.per-file-ignores."testing/code/test_source.py" = [
"F841",
Expand Down Expand Up @@ -217,31 +219,30 @@ disable = [
"comparison-with-callable",
"comparison-with-itself", # PLR0124 from ruff
"condition-evals-to-constant",
"consider-alternative-union-syntax",
"confusing-consecutive-elif",
"consider-alternative-union-syntax",
"consider-ternary-expression",
"consider-using-assignment-expr",
"consider-using-dict-items",
"consider-using-from-import",
"consider-using-from-import", # not activated by default, PLR0402 disabled in ruff
"consider-using-f-string",
"consider-using-in",
"consider-using-namedtuple-or-dataclass",
"consider-using-ternary",
"consider-using-tuple",
"consider-using-with",
"consider-using-from-import", # not activated by default, PLR0402 disabled in ruff
"consider-ternary-expression",
"cyclic-import",
"differing-param-doc",
"docstring-first-line-empty",
"deprecated-argument",
"deprecated-attribute",
"deprecated-class",
"differing-param-doc",
"disallowed-name", # foo / bar are used often in tests
"docstring-first-line-empty",
"duplicate-code",
"else-if-used", # not activated by default, PLR5501 disabled in ruff
"empty-comment", # not activated by default, PLR2044 disabled in ruff
"eval-used",
"eq-without-hash", # PLW1641 disabled in ruff
"eval-used",
"exec-used",
"expression-not-assigned",
"fixme",
Expand All @@ -258,13 +259,13 @@ disable = [
"line-too-long",
"magic-value-comparison", # not activated by default, PLR2004 disabled in ruff
"method-hidden",
"misplaced-bare-raise", # PLE0704 from ruff
"misplaced-comparison-constant",
"missing-docstring",
"missing-param-doc",
"missing-raises-doc",
"missing-timeout",
"missing-type-doc",
"misplaced-bare-raise", # PLE0704 from ruff
"misplaced-comparison-constant",
"multiple-statements", # multiple-statements-on-one-line-colon (E701) from ruff
"no-else-break",
"no-else-continue",
Expand Down Expand Up @@ -329,10 +330,10 @@ disable = [
"use-dict-literal",
"use-implicit-booleaness-not-comparison",
"use-implicit-booleaness-not-len",
"use-set-for-membership",
"useless-else-on-loop", # PLC0414 disabled in ruff
"useless-import-alias",
"useless-return",
"use-set-for-membership",
"using-constant-test",
"while-used",
"wrong-import-order", # handled by isort / ruff
Expand Down
2 changes: 1 addition & 1 deletion src/_pytest/config/findpaths.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def is_option(x: str) -> bool:
return x.startswith("-")

def get_file_part_from_node_id(x: str) -> str:
return x.split("::")[0]
return x.split("::", maxsplit=1)[0]

def get_dir_from_path(path: Path) -> Path:
if path.is_dir():
Expand Down
6 changes: 4 additions & 2 deletions src/_pytest/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ def hasopt(self, char: str) -> bool:
return char in self.reportchars

def write_fspath_result(self, nodeid: str, res: str, **markup: bool) -> None:
fspath = self.config.rootpath / nodeid.split("::")[0]
fspath = self.config.rootpath / nodeid.split("::", maxsplit=1)[0]
if self.currentfspath is None or fspath != self.currentfspath:
if self.currentfspath is not None and self._show_progress_info:
self._write_progress_information_filling_space()
Expand Down Expand Up @@ -1034,7 +1034,9 @@ def mkrel(nodeid: str) -> str:
# fspath comes from testid which has a "/"-normalized path.
if fspath:
res = mkrel(nodeid)
if self.verbosity >= 2 and nodeid.split("::")[0] != nodes.norm_sep(fspath):
if self.verbosity >= 2 and (
nodeid.split("::", maxsplit=1)[0] != nodes.norm_sep(fspath)
):
res += " <- " + bestrelpath(self.startpath, Path(fspath))
else:
res = "[location]"
Expand Down
5 changes: 3 additions & 2 deletions src/_pytest/timing.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ class Instant:

# Creation time of this instant, using time.time(), to measure actual time.
# Note: using a `lambda` to correctly get the mocked time via `MockTiming`.
time: float = dataclasses.field(default_factory=lambda: time(), init=False)
time: float = dataclasses.field(default_factory=lambda: time(), init=False) # noqa: PLW0108

# Performance counter tick of the instant, used to measure precise elapsed time.
# Note: using a `lambda` to correctly get the mocked time via `MockTiming`.
perf_count: float = dataclasses.field(
default_factory=lambda: perf_counter(), init=False
default_factory=lambda: perf_counter(), # noqa: PLW0108
init=False,
)

def elapsed(self) -> Duration:
Expand Down
2 changes: 1 addition & 1 deletion testing/_py/test_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -1388,7 +1388,7 @@ def test_stat_helpers(self, tmpdir, monkeypatch):

def test_stat_non_raising(self, tmpdir):
path1 = tmpdir.join("file")
pytest.raises(error.ENOENT, lambda: path1.stat())
pytest.raises(error.ENOENT, path1.stat)
res = path1.stat(raising=False)
assert res is None

Expand Down