Skip to content

Commit

Permalink
fix pytest-dev#8361: address review/quality comments
Browse files Browse the repository at this point in the history
  • Loading branch information
RonnyPfannschmidt committed Mar 29, 2021
1 parent 7ac7610 commit bad1963
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
14 changes: 14 additions & 0 deletions doc/en/deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,20 @@ Below is a complete list of all pytest features which are considered deprecated.
:class:`PytestWarning` or subclasses, which can be filtered using :ref:`standard warning filters <warnings>`.


``py.path.local`` arguments for hooks replaced with ``pathlib.Path``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

In order to support the transition oto pathlib, the following hooks added additional arugments:

* ``pytest_ignore_collect(fspath: pathlib.Path)``
* ``pytest_collect_file(fspath: pathlib.Path)``
* ``pytest_pycollect_makemodule(fspath: pathlib.Path)``
* ``pytest_report_header(startpath: pathlib.Path)``
* ``pytest_report_collectionfinish(startpath: pathlib.Path)``

The accompanying ``py.path.local`` based paths have been deprecated.


``Node.fspath`` in favor of ``pathlib`` and ``Node.path``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
19 changes: 16 additions & 3 deletions src/_pytest/config/compat.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import functools
import warnings
from pathlib import Path
from typing import Optional
Expand All @@ -17,20 +18,31 @@


class PathAwareHookProxy:
"""
this helper wraps around hook callers
until pluggy supports fixingcalls, this one will do
it currently doesnt return full hook caller proxies for fixed hooks,
this may have to be changed later depending on bugs
"""

def __init__(self, hook_caller):
self.__hook_caller = hook_caller

def __dir__(self):
return dir(self.__hook_caller)

def __getattr__(self, key):
def __getattr__(self, key, _wraps=functools.wraps):
hook = getattr(self.__hook_caller, key)
if key not in imply_paths_hooks:
return getattr(self.__hook_caller, key)
self.__dict__[key] = hook
return hook
else:
hook = getattr(self.__hook_caller, key)
path_var, fspath_var = imply_paths_hooks[key]

@_wraps(hook)
def fixed_hook(**kw):

path_value: Optional[Path] = kw.pop(path_var, None)
fspath_value: Optional[LEGACY_PATH] = kw.pop(fspath_var, None)
if fspath_value is not None:
Expand All @@ -45,4 +57,5 @@ def fixed_hook(**kw):
return hook(**kw)

fixed_hook.__name__ = key
self.__dict__[key] = fixed_hook
return fixed_hook
4 changes: 3 additions & 1 deletion src/_pytest/deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@

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

0 comments on commit bad1963

Please sign in to comment.