Skip to content

Commit 899a84f

Browse files
authored
Merge pull request #13956 from bluetech/rm-removed-in-9
Start final removal of features deprecated for pytest 9
2 parents 342dba6 + 86608c3 commit 899a84f

File tree

10 files changed

+107
-306
lines changed

10 files changed

+107
-306
lines changed

doc/en/deprecations.rst

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -334,33 +334,6 @@ Changed ``hookwrapper`` attributes:
334334
* ``historic``
335335

336336

337-
.. _legacy-path-hooks-deprecated:
338-
339-
``py.path.local`` arguments for hooks replaced with ``pathlib.Path``
340-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
341-
342-
.. deprecated:: 7.0
343-
344-
In order to support the transition from ``py.path.local`` to :mod:`pathlib`, the following hooks now receive additional arguments:
345-
346-
* :hook:`pytest_ignore_collect(collection_path: pathlib.Path) <pytest_ignore_collect>` as equivalent to ``path``
347-
* :hook:`pytest_collect_file(file_path: pathlib.Path) <pytest_collect_file>` as equivalent to ``path``
348-
* :hook:`pytest_pycollect_makemodule(module_path: pathlib.Path) <pytest_pycollect_makemodule>` as equivalent to ``path``
349-
* :hook:`pytest_report_header(start_path: pathlib.Path) <pytest_report_header>` as equivalent to ``startdir``
350-
* :hook:`pytest_report_collectionfinish(start_path: pathlib.Path) <pytest_report_collectionfinish>` as equivalent to ``startdir``
351-
352-
The accompanying ``py.path.local`` based paths have been deprecated: plugins which manually invoke those hooks should only pass the new ``pathlib.Path`` arguments, and users should change their hook implementations to use the new ``pathlib.Path`` arguments.
353-
354-
.. note::
355-
The name of the :class:`~_pytest.nodes.Node` arguments and attributes,
356-
:ref:`outlined above <node-ctor-fspath-deprecation>` (the new attribute
357-
being ``path``) is **the opposite** of the situation for hooks (the old
358-
argument being ``path``).
359-
360-
This is an unfortunate artifact due to historical reasons, which should be
361-
resolved in future versions as we slowly get rid of the :pypi:`py`
362-
dependency (see :issue:`9283` for a longer discussion).
363-
364337
Directly constructing internal classes
365338
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
366339

@@ -431,10 +404,30 @@ conflicts (such as :class:`pytest.File` now taking ``path`` instead of
431404
``fspath``, as :ref:`outlined above <node-ctor-fspath-deprecation>`), a
432405
deprecation warning is now raised.
433406

407+
408+
The ``yield_fixture`` function/decorator
409+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
410+
411+
.. deprecated:: 6.2
412+
413+
``pytest.yield_fixture`` is a deprecated alias for :func:`pytest.fixture`.
414+
415+
It has been so for a very long time, so can be search/replaced safely.
416+
417+
418+
Removed Features and Breaking Changes
419+
-------------------------------------
420+
421+
As stated in our :ref:`backwards-compatibility` policy, deprecated features are removed only in major releases after
422+
an appropriate period of deprecation has passed.
423+
424+
Some breaking changes which could not be deprecated are also listed.
425+
434426
Applying a mark to a fixture function
435427
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
436428

437429
.. deprecated:: 7.4
430+
.. versionremoved:: 9.0
438431

439432
Applying a mark to a fixture function never had any effect, but it is a common user error.
440433

@@ -448,24 +441,33 @@ Users expected in this case that the ``usefixtures`` mark would have its intende
448441

449442
Now pytest will issue a warning when it encounters this problem, and will raise an error in the future versions.
450443

444+
.. _legacy-path-hooks-deprecated:
451445

452-
The ``yield_fixture`` function/decorator
453-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
454-
455-
.. deprecated:: 6.2
446+
``py.path.local`` arguments for hooks replaced with ``pathlib.Path``
447+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
456448

457-
``pytest.yield_fixture`` is a deprecated alias for :func:`pytest.fixture`.
449+
.. deprecated:: 7.0
450+
.. versionremoved:: 9.0
458451

459-
It has been so for a very long time, so can be search/replaced safely.
452+
In order to support the transition from ``py.path.local`` to :mod:`pathlib`, the following hooks now receive additional arguments:
460453

454+
* :hook:`pytest_ignore_collect(collection_path: pathlib.Path) <pytest_ignore_collect>` as equivalent to ``path``
455+
* :hook:`pytest_collect_file(file_path: pathlib.Path) <pytest_collect_file>` as equivalent to ``path``
456+
* :hook:`pytest_pycollect_makemodule(module_path: pathlib.Path) <pytest_pycollect_makemodule>` as equivalent to ``path``
457+
* :hook:`pytest_report_header(start_path: pathlib.Path) <pytest_report_header>` as equivalent to ``startdir``
458+
* :hook:`pytest_report_collectionfinish(start_path: pathlib.Path) <pytest_report_collectionfinish>` as equivalent to ``startdir``
461459

462-
Removed Features and Breaking Changes
463-
-------------------------------------
460+
The accompanying ``py.path.local`` based paths have been deprecated: plugins which manually invoke those hooks should only pass the new ``pathlib.Path`` arguments, and users should change their hook implementations to use the new ``pathlib.Path`` arguments.
464461

465-
As stated in our :ref:`backwards-compatibility` policy, deprecated features are removed only in major releases after
466-
an appropriate period of deprecation has passed.
462+
.. note::
463+
The name of the :class:`~_pytest.nodes.Node` arguments and attributes,
464+
:ref:`outlined above <node-ctor-fspath-deprecation>` (the new attribute
465+
being ``path``) is **the opposite** of the situation for hooks (the old
466+
argument being ``path``).
467467

468-
Some breaking changes which could not be deprecated are also listed.
468+
This is an unfortunate artifact due to historical reasons, which should be
469+
resolved in future versions as we slowly get rid of the :pypi:`py`
470+
dependency (see :issue:`9283` for a longer discussion).
469471

470472
.. _yield tests deprecated:
471473

src/_pytest/config/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,12 @@
3939
from typing import TYPE_CHECKING
4040
import warnings
4141

42-
import pluggy
4342
from pluggy import HookimplMarker
4443
from pluggy import HookimplOpts
4544
from pluggy import HookspecMarker
4645
from pluggy import HookspecOpts
4746
from pluggy import PluginManager
4847

49-
from .compat import PathAwareHookProxy
5048
from .exceptions import PrintHelp as PrintHelp
5149
from .exceptions import UsageError as UsageError
5250
from .findpaths import ConfigDict
@@ -1116,7 +1114,7 @@ def __init__(
11161114
self._store = self.stash
11171115

11181116
self.trace = self.pluginmanager.trace.root.get("config")
1119-
self.hook: pluggy.HookRelay = PathAwareHookProxy(self.pluginmanager.hook) # type: ignore[assignment]
1117+
self.hook = self.pluginmanager.hook
11201118
self._inicache: dict[str, Any] = {}
11211119
self._inicfg: ConfigDict = {}
11221120
self._cleanup_stack = contextlib.ExitStack()

src/_pytest/config/compat.py

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,8 @@
11
from __future__ import annotations
22

3-
from collections.abc import Mapping
4-
import functools
53
from pathlib import Path
6-
from typing import Any
7-
import warnings
8-
9-
import pluggy
104

115
from ..compat import LEGACY_PATH
12-
from ..compat import legacy_path
13-
from ..deprecated import HOOK_LEGACY_PATH_ARG
14-
15-
16-
# hookname: (Path, LEGACY_PATH)
17-
imply_paths_hooks: Mapping[str, tuple[str, str]] = {
18-
"pytest_ignore_collect": ("collection_path", "path"),
19-
"pytest_collect_file": ("file_path", "path"),
20-
"pytest_pycollect_makemodule": ("module_path", "path"),
21-
"pytest_report_header": ("start_path", "startdir"),
22-
"pytest_report_collectionfinish": ("start_path", "startdir"),
23-
}
246

257

268
def _check_path(path: Path, fspath: LEGACY_PATH) -> None:
@@ -29,57 +11,3 @@ def _check_path(path: Path, fspath: LEGACY_PATH) -> None:
2911
f"Path({fspath!r}) != {path!r}\n"
3012
"if both path and fspath are given they need to be equal"
3113
)
32-
33-
34-
class PathAwareHookProxy:
35-
"""
36-
this helper wraps around hook callers
37-
until pluggy supports fixingcalls, this one will do
38-
39-
it currently doesn't return full hook caller proxies for fixed hooks,
40-
this may have to be changed later depending on bugs
41-
"""
42-
43-
def __init__(self, hook_relay: pluggy.HookRelay) -> None:
44-
self._hook_relay = hook_relay
45-
46-
def __dir__(self) -> list[str]:
47-
return dir(self._hook_relay)
48-
49-
def __getattr__(self, key: str) -> pluggy.HookCaller:
50-
hook: pluggy.HookCaller = getattr(self._hook_relay, key)
51-
if key not in imply_paths_hooks:
52-
self.__dict__[key] = hook
53-
return hook
54-
else:
55-
path_var, fspath_var = imply_paths_hooks[key]
56-
57-
@functools.wraps(hook)
58-
def fixed_hook(**kw: Any) -> Any:
59-
path_value: Path | None = kw.pop(path_var, None)
60-
fspath_value: LEGACY_PATH | None = kw.pop(fspath_var, None)
61-
if fspath_value is not None:
62-
warnings.warn(
63-
HOOK_LEGACY_PATH_ARG.format(
64-
pylib_path_arg=fspath_var, pathlib_path_arg=path_var
65-
),
66-
stacklevel=2,
67-
)
68-
if path_value is not None:
69-
if fspath_value is not None:
70-
_check_path(path_value, fspath_value)
71-
else:
72-
fspath_value = legacy_path(path_value)
73-
else:
74-
assert fspath_value is not None
75-
path_value = Path(fspath_value)
76-
77-
kw[path_var] = path_value
78-
kw[fspath_var] = fspath_value
79-
return hook(**kw)
80-
81-
fixed_hook.name = hook.name # type: ignore[attr-defined]
82-
fixed_hook.spec = hook.spec # type: ignore[attr-defined]
83-
fixed_hook.__name__ = key
84-
self.__dict__[key] = fixed_hook
85-
return fixed_hook # type: ignore[return-value]

src/_pytest/deprecated.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,6 @@
3939
PRIVATE = PytestDeprecationWarning("A private pytest class or function was used.")
4040

4141

42-
HOOK_LEGACY_PATH_ARG = UnformattedWarning(
43-
PytestRemovedIn9Warning,
44-
"The ({pylib_path_arg}: py.path.local) argument is deprecated, please use ({pathlib_path_arg}: pathlib.Path)\n"
45-
"see https://docs.pytest.org/en/latest/deprecations.html"
46-
"#py-path-local-arguments-for-hooks-replaced-with-pathlib-path",
47-
)
48-
4942
NODE_CTOR_FSPATH_ARG = UnformattedWarning(
5043
PytestRemovedIn9Warning,
5144
"The (fspath: py.path.local) argument to {node_type_name} is deprecated. "
@@ -63,11 +56,6 @@
6356
"#configuring-hook-specs-impls-using-markers",
6457
)
6558

66-
MARKED_FIXTURE = PytestRemovedIn9Warning(
67-
"Marks applied to fixtures have no effect\n"
68-
"See docs: https://docs.pytest.org/en/stable/deprecations.html#applying-a-mark-to-a-fixture-function"
69-
)
70-
7159
MONKEYPATCH_LEGACY_NAMESPACE_PACKAGES = PytestRemovedIn10Warning(
7260
"monkeypatch.syspath_prepend() called with pkg_resources legacy namespace packages detected.\n"
7361
"Legacy namespace packages (using pkg_resources.declare_namespace) are deprecated.\n"

src/_pytest/fixtures.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
from _pytest.config import ExitCode
5555
from _pytest.config.argparsing import Parser
5656
from _pytest.deprecated import check_ispytest
57-
from _pytest.deprecated import MARKED_FIXTURE
5857
from _pytest.deprecated import YIELD_FIXTURE
5958
from _pytest.main import Session
6059
from _pytest.mark import ParameterSet
@@ -1231,7 +1230,10 @@ def __call__(self, function: FixtureFunction) -> FixtureFunctionDefinition:
12311230
)
12321231

12331232
if hasattr(function, "pytestmark"):
1234-
warnings.warn(MARKED_FIXTURE, stacklevel=2)
1233+
fail(
1234+
"Marks cannot be applied to fixtures.\n"
1235+
"See docs: https://docs.pytest.org/en/stable/deprecations.html#applying-a-mark-to-a-fixture-function"
1236+
)
12351237

12361238
fixture_definition = FixtureFunctionDefinition(
12371239
function=function, fixture_function_marker=self, _ispytest=True

0 commit comments

Comments
 (0)