Skip to content

Commit 39a05ff

Browse files
authored
Merge branch 'main' into issue-11225
2 parents b4e2d97 + 2ca0f8a commit 39a05ff

9 files changed

Lines changed: 207 additions & 124 deletions

File tree

.pre-commit-config.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
minimum_pre_commit_version: "4.4.0"
22
repos:
33
- repo: https://github.com/astral-sh/ruff-pre-commit
4-
rev: "v0.14.14"
4+
rev: "v0.15.7"
55
hooks:
66
- id: ruff-check
77
args: ["--fix"]
@@ -13,7 +13,7 @@ repos:
1313
- id: end-of-file-fixer
1414
- id: check-yaml
1515
- repo: https://github.com/woodruffw/zizmor-pre-commit
16-
rev: v1.22.0
16+
rev: v1.23.1
1717
hooks:
1818
- id: zizmor
1919
args: ["--fix", "--no-progress"]
@@ -23,7 +23,7 @@ repos:
2323
- id: blacken-docs
2424
additional_dependencies: [black==24.1.1]
2525
- repo: https://github.com/codespell-project/codespell
26-
rev: v2.4.1
26+
rev: v2.4.2
2727
hooks:
2828
- id: codespell
2929
args: ["--toml=pyproject.toml"]
@@ -67,7 +67,7 @@ repos:
6767
- exceptiongroup>=1.0.0rc8
6868
# Manual because passing pyright is a work in progress.
6969
stages: [manual]
70-
- repo: https://github.com/tox-dev/pyproject-fmt
70+
- repo: https://github.com/pytest-dev/pyproject-fmt
7171
rev: "v2.12.1"
7272
hooks:
7373
- id: pyproject-fmt

doc/en/reference/plugin_list.rst

Lines changed: 167 additions & 63 deletions
Large diffs are not rendered by default.

pyproject.toml

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ lint.ignore = [
161161
"PLW2901", # for loop variable overwritten by assignment target
162162
# ruff ignore
163163
"RUF012", # Mutable class attributes should be annotated with `typing.ClassVar`
164+
"RUF061", # Use context-manager form of `pytest.raises()`
164165
]
165166
lint.per-file-ignores."src/_pytest/_py/**/*.py" = [
166167
"B",
@@ -169,6 +170,8 @@ lint.per-file-ignores."src/_pytest/_py/**/*.py" = [
169170
lint.per-file-ignores."src/_pytest/_version.py" = [
170171
"I001",
171172
]
173+
# 'Unnecessary membership test on empty collection', always voluntary in tests
174+
lint.per-file-ignores."testing/**/*.py" = [ "RUF060" ]
172175
# can't be disabled on a line-by-line basis in file
173176
lint.per-file-ignores."testing/code/test_source.py" = [
174177
"F841",
@@ -217,31 +220,30 @@ disable = [
217220
"comparison-with-callable",
218221
"comparison-with-itself", # PLR0124 from ruff
219222
"condition-evals-to-constant",
220-
"consider-alternative-union-syntax",
221223
"confusing-consecutive-elif",
224+
"consider-alternative-union-syntax",
225+
"consider-ternary-expression",
222226
"consider-using-assignment-expr",
223227
"consider-using-dict-items",
224-
"consider-using-from-import",
228+
"consider-using-from-import", # not activated by default, PLR0402 disabled in ruff
225229
"consider-using-f-string",
226230
"consider-using-in",
227231
"consider-using-namedtuple-or-dataclass",
228232
"consider-using-ternary",
229233
"consider-using-tuple",
230234
"consider-using-with",
231-
"consider-using-from-import", # not activated by default, PLR0402 disabled in ruff
232-
"consider-ternary-expression",
233235
"cyclic-import",
234-
"differing-param-doc",
235-
"docstring-first-line-empty",
236236
"deprecated-argument",
237237
"deprecated-attribute",
238238
"deprecated-class",
239+
"differing-param-doc",
239240
"disallowed-name", # foo / bar are used often in tests
241+
"docstring-first-line-empty",
240242
"duplicate-code",
241243
"else-if-used", # not activated by default, PLR5501 disabled in ruff
242244
"empty-comment", # not activated by default, PLR2044 disabled in ruff
243-
"eval-used",
244245
"eq-without-hash", # PLW1641 disabled in ruff
246+
"eval-used",
245247
"exec-used",
246248
"expression-not-assigned",
247249
"fixme",
@@ -258,13 +260,13 @@ disable = [
258260
"line-too-long",
259261
"magic-value-comparison", # not activated by default, PLR2004 disabled in ruff
260262
"method-hidden",
263+
"misplaced-bare-raise", # PLE0704 from ruff
264+
"misplaced-comparison-constant",
261265
"missing-docstring",
262266
"missing-param-doc",
263267
"missing-raises-doc",
264268
"missing-timeout",
265269
"missing-type-doc",
266-
"misplaced-bare-raise", # PLE0704 from ruff
267-
"misplaced-comparison-constant",
268270
"multiple-statements", # multiple-statements-on-one-line-colon (E701) from ruff
269271
"no-else-break",
270272
"no-else-continue",
@@ -329,10 +331,10 @@ disable = [
329331
"use-dict-literal",
330332
"use-implicit-booleaness-not-comparison",
331333
"use-implicit-booleaness-not-len",
332-
"use-set-for-membership",
333334
"useless-else-on-loop", # PLC0414 disabled in ruff
334335
"useless-import-alias",
335336
"useless-return",
337+
"use-set-for-membership",
336338
"using-constant-test",
337339
"while-used",
338340
"wrong-import-order", # handled by isort / ruff

src/_pytest/config/__init__.py

Lines changed: 14 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,8 @@ def _set_initial_conftests(
589589
)
590590
self._noconftest = noconftest
591591
self._using_pyargs = pyargs
592-
foundanchor = False
592+
593+
anchors = []
593594
for initial_path in args:
594595
path = str(initial_path)
595596
# remove node-id syntax
@@ -601,16 +602,18 @@ def _set_initial_conftests(
601602
# Ensure we do not break if what appears to be an anchor
602603
# is in fact a very long option (#10169, #11394).
603604
if safe_exists(anchor):
604-
self._try_load_conftest(
605-
anchor,
606-
importmode,
607-
rootpath,
608-
consider_namespace_packages=consider_namespace_packages,
609-
)
610-
foundanchor = True
611-
if not foundanchor:
612-
self._try_load_conftest(
613-
invocation_dir,
605+
anchors.append(anchor)
606+
# Let's also consider test* subdirs.
607+
if anchor.is_dir():
608+
for x in anchor.glob("test*"):
609+
if x.is_dir():
610+
anchors.append(x)
611+
if not anchors:
612+
anchors = [invocation_dir]
613+
614+
for anchor in anchors:
615+
self._loadconftestmodules(
616+
anchor,
614617
importmode,
615618
rootpath,
616619
consider_namespace_packages=consider_namespace_packages,
@@ -631,31 +634,6 @@ def _is_in_confcutdir(self, path: pathlib.Path) -> bool:
631634
# (see #9767 for a regression where the logic was inverted).
632635
return path not in self._confcutdir.parents
633636

634-
def _try_load_conftest(
635-
self,
636-
anchor: pathlib.Path,
637-
importmode: str | ImportMode,
638-
rootpath: pathlib.Path,
639-
*,
640-
consider_namespace_packages: bool,
641-
) -> None:
642-
self._loadconftestmodules(
643-
anchor,
644-
importmode,
645-
rootpath,
646-
consider_namespace_packages=consider_namespace_packages,
647-
)
648-
# let's also consider test* subdirs
649-
if anchor.is_dir():
650-
for x in anchor.glob("test*"):
651-
if x.is_dir():
652-
self._loadconftestmodules(
653-
x,
654-
importmode,
655-
rootpath,
656-
consider_namespace_packages=consider_namespace_packages,
657-
)
658-
659637
def _loadconftestmodules(
660638
self,
661639
path: pathlib.Path,

src/_pytest/config/findpaths.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ def is_option(x: str) -> bool:
233233
return x.startswith("-")
234234

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

238238
def get_dir_from_path(path: Path) -> Path:
239239
if path.is_dir():

src/_pytest/hookspec.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,6 @@ def pytest_ignore_collect(collection_path: Path, config: Config) -> bool | None:
315315
316316
:param collection_path: The path to analyze.
317317
:type collection_path: pathlib.Path
318-
:param path: The path to analyze (deprecated).
319318
:param config: The pytest config object.
320319
321320
.. versionchanged:: 7.0.0
@@ -373,7 +372,6 @@ def pytest_collect_file(file_path: Path, parent: Collector) -> Collector | None:
373372
374373
:param file_path: The path to analyze.
375374
:type file_path: pathlib.Path
376-
:param path: The path to collect (deprecated).
377375
378376
.. versionchanged:: 7.0.0
379377
The ``file_path`` parameter was added as a :class:`pathlib.Path`
@@ -492,7 +490,6 @@ def pytest_pycollect_makemodule(module_path: Path, parent) -> Module | None:
492490
493491
:param module_path: The path of the module to collect.
494492
:type module_path: pathlib.Path
495-
:param path: The path of the module to collect (deprecated).
496493
497494
.. versionchanged:: 7.0.0
498495
The ``module_path`` parameter was added as a :class:`pathlib.Path`
@@ -1011,7 +1008,6 @@ def pytest_report_header(config: Config, start_path: Path) -> str | list[str]:
10111008
:param config: The pytest config object.
10121009
:param start_path: The starting dir.
10131010
:type start_path: pathlib.Path
1014-
:param startdir: The starting dir (deprecated).
10151011
10161012
.. note::
10171013
@@ -1047,7 +1043,6 @@ def pytest_report_collectionfinish( # type: ignore[empty-body]
10471043
:param config: The pytest config object.
10481044
:param start_path: The starting dir.
10491045
:type start_path: pathlib.Path
1050-
:param startdir: The starting dir (deprecated).
10511046
:param items: List of pytest items that are going to be executed; this list should not be modified.
10521047
10531048
.. note::

src/_pytest/terminal.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ def hasopt(self, char: str) -> bool:
476476
return char in self.reportchars
477477

478478
def write_fspath_result(self, nodeid: str, res: str, **markup: bool) -> None:
479-
fspath = self.config.rootpath / nodeid.split("::")[0]
479+
fspath = self.config.rootpath / nodeid.split("::", maxsplit=1)[0]
480480
if self.currentfspath is None or fspath != self.currentfspath:
481481
if self.currentfspath is not None and self._show_progress_info:
482482
self._write_progress_information_filling_space()
@@ -1034,7 +1034,9 @@ def mkrel(nodeid: str) -> str:
10341034
# fspath comes from testid which has a "/"-normalized path.
10351035
if fspath:
10361036
res = mkrel(nodeid)
1037-
if self.verbosity >= 2 and nodeid.split("::")[0] != nodes.norm_sep(fspath):
1037+
if self.verbosity >= 2 and (
1038+
nodeid.split("::", maxsplit=1)[0] != nodes.norm_sep(fspath)
1039+
):
10381040
res += " <- " + bestrelpath(self.startpath, Path(fspath))
10391041
else:
10401042
res = "[location]"

src/_pytest/timing.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,14 @@ class Instant:
3232

3333
# Creation time of this instant, using time.time(), to measure actual time.
3434
# Note: using a `lambda` to correctly get the mocked time via `MockTiming`.
35-
time: float = dataclasses.field(default_factory=lambda: time(), init=False)
35+
# pylint: disable-next=lambda-assignment
36+
time: float = dataclasses.field(default_factory=lambda: time(), init=False) # noqa: PLW0108
3637

3738
# Performance counter tick of the instant, used to measure precise elapsed time.
3839
# Note: using a `lambda` to correctly get the mocked time via `MockTiming`.
3940
perf_count: float = dataclasses.field(
40-
default_factory=lambda: perf_counter(), init=False
41+
default_factory=lambda: perf_counter(), # noqa: PLW0108
42+
init=False,
4143
)
4244

4345
def elapsed(self) -> Duration:

testing/_py/test_local.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1388,7 +1388,7 @@ def test_stat_helpers(self, tmpdir, monkeypatch):
13881388

13891389
def test_stat_non_raising(self, tmpdir):
13901390
path1 = tmpdir.join("file")
1391-
pytest.raises(error.ENOENT, lambda: path1.stat())
1391+
pytest.raises(error.ENOENT, path1.stat)
13921392
res = path1.stat(raising=False)
13931393
assert res is None
13941394

0 commit comments

Comments
 (0)