Skip to content

Commit bad1963

Browse files
fix #8361: address review/quality comments
1 parent 7ac7610 commit bad1963

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

doc/en/deprecations.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,20 @@ Below is a complete list of all pytest features which are considered deprecated.
1919
:class:`PytestWarning` or subclasses, which can be filtered using :ref:`standard warning filters <warnings>`.
2020

2121

22+
``py.path.local`` arguments for hooks replaced with ``pathlib.Path``
23+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
24+
25+
In order to support the transition oto pathlib, the following hooks added additional arugments:
26+
27+
* ``pytest_ignore_collect(fspath: pathlib.Path)``
28+
* ``pytest_collect_file(fspath: pathlib.Path)``
29+
* ``pytest_pycollect_makemodule(fspath: pathlib.Path)``
30+
* ``pytest_report_header(startpath: pathlib.Path)``
31+
* ``pytest_report_collectionfinish(startpath: pathlib.Path)``
32+
33+
The accompanying ``py.path.local`` based paths have been deprecated.
34+
35+
2236
``Node.fspath`` in favor of ``pathlib`` and ``Node.path``
2337
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2438

src/_pytest/config/compat.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import functools
12
import warnings
23
from pathlib import Path
34
from typing import Optional
@@ -17,20 +18,31 @@
1718

1819

1920
class PathAwareHookProxy:
21+
"""
22+
this helper wraps around hook callers
23+
until pluggy supports fixingcalls, this one will do
24+
25+
it currently doesnt return full hook caller proxies for fixed hooks,
26+
this may have to be changed later depending on bugs
27+
"""
28+
2029
def __init__(self, hook_caller):
2130
self.__hook_caller = hook_caller
2231

2332
def __dir__(self):
2433
return dir(self.__hook_caller)
2534

26-
def __getattr__(self, key):
35+
def __getattr__(self, key, _wraps=functools.wraps):
36+
hook = getattr(self.__hook_caller, key)
2737
if key not in imply_paths_hooks:
28-
return getattr(self.__hook_caller, key)
38+
self.__dict__[key] = hook
39+
return hook
2940
else:
30-
hook = getattr(self.__hook_caller, key)
3141
path_var, fspath_var = imply_paths_hooks[key]
3242

43+
@_wraps(hook)
3344
def fixed_hook(**kw):
45+
3446
path_value: Optional[Path] = kw.pop(path_var, None)
3547
fspath_value: Optional[LEGACY_PATH] = kw.pop(fspath_var, None)
3648
if fspath_value is not None:
@@ -45,4 +57,5 @@ def fixed_hook(**kw):
4557
return hook(**kw)
4658

4759
fixed_hook.__name__ = key
60+
self.__dict__[key] = fixed_hook
4861
return fixed_hook

src/_pytest/deprecated.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@
9797

9898
HOOK_LEGACY_PATH_ARG = UnformattedWarning(
9999
PytestDeprecationWarning,
100-
"{pylib_path_arg} : py.path.local is deprecated, please use {pathlib_path_arg} : pathlib.Path",
100+
"The ({pylib_path_arg}: py.path.local) argument is deprecated, please use ({pathlib_path_arg}: pathlib.Path)\n"
101+
"see https://docs.pytest.org/en/latest/deprecations.html"
102+
"#py-path-local-arguments-for-hooks-replaced-with-pathlib-path",
101103
)
102104
# You want to make some `__init__` or function "private".
103105
#

0 commit comments

Comments
 (0)