Skip to content

Commit

Permalink
Merge pull request #9208 from bluetech/legacypath-plugin
Browse files Browse the repository at this point in the history
Add legacypath plugin, move py.path stuff there
  • Loading branch information
bluetech committed Nov 2, 2021
2 parents e1b3c2d + e6eac28 commit a53abe9
Show file tree
Hide file tree
Showing 18 changed files with 647 additions and 448 deletions.
4 changes: 4 additions & 0 deletions doc/en/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,3 +460,7 @@ def patched_is_final(self, decorators: List[ast.expr]) -> bool:
)

sphinx.pycode.parser.VariableCommentPicker.is_final = patched_is_final

# legacypath.py monkey-patches pytest.Testdir in. Import the file so
# that autodoc can discover references to it.
import _pytest.legacypath # noqa: F401
2 changes: 1 addition & 1 deletion doc/en/reference/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ tmpdir

:ref:`tmpdir and tmpdir_factory`

.. autofunction:: _pytest.tmpdir.tmpdir()
.. autofunction:: _pytest.legacypath.LegacyTmpdirPlugin.tmpdir()
:no-auto-options:


Expand Down
9 changes: 0 additions & 9 deletions src/_pytest/cacheprovider.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
from _pytest import nodes
from _pytest._io import TerminalWriter
from _pytest.compat import final
from _pytest.compat import LEGACY_PATH
from _pytest.compat import legacy_path
from _pytest.config import Config
from _pytest.config import ExitCode
from _pytest.config import hookimpl
Expand Down Expand Up @@ -142,13 +140,6 @@ def mkdir(self, name: str) -> Path:
res.mkdir(exist_ok=True, parents=True)
return res

def makedir(self, name: str) -> LEGACY_PATH:
"""Return a directory path object with the given name.
Same as :func:`mkdir`, but returns a legacy py path instance.
"""
return legacy_path(self.mkdir(name))

def _getvaluepath(self, key: str) -> Path:
return self._cachedir.joinpath(self._CACHE_PREFIX_VALUES, Path(key))

Expand Down
55 changes: 13 additions & 42 deletions src/_pytest/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@
from _pytest._io import TerminalWriter
from _pytest.compat import final
from _pytest.compat import importlib_metadata
from _pytest.compat import LEGACY_PATH
from _pytest.compat import legacy_path
from _pytest.outcomes import fail
from _pytest.outcomes import Skipped
from _pytest.pathlib import absolutepath
Expand Down Expand Up @@ -240,6 +238,7 @@ def directory_arg(path: str, optname: str) -> str:
"unittest",
"capture",
"skipping",
"legacypath",
"tmpdir",
"monkeypatch",
"recwarn",
Expand Down Expand Up @@ -949,17 +948,6 @@ def __init__(

self.cache: Optional[Cache] = None

@property
def invocation_dir(self) -> LEGACY_PATH:
"""The directory from which pytest was invoked.
Prefer to use :attr:`invocation_params.dir <InvocationParams.dir>`,
which is a :class:`pathlib.Path`.
:type: LEGACY_PATH
"""
return legacy_path(str(self.invocation_params.dir))

@property
def rootpath(self) -> Path:
"""The path to the :ref:`rootdir <rootdir>`.
Expand All @@ -970,16 +958,6 @@ def rootpath(self) -> Path:
"""
return self._rootpath

@property
def rootdir(self) -> LEGACY_PATH:
"""The path to the :ref:`rootdir <rootdir>`.
Prefer to use :attr:`rootpath`, which is a :class:`pathlib.Path`.
:type: LEGACY_PATH
"""
return legacy_path(str(self.rootpath))

@property
def inipath(self) -> Optional[Path]:
"""The path to the :ref:`configfile <configfiles>`.
Expand All @@ -990,16 +968,6 @@ def inipath(self) -> Optional[Path]:
"""
return self._inipath

@property
def inifile(self) -> Optional[LEGACY_PATH]:
"""The path to the :ref:`configfile <configfiles>`.
Prefer to use :attr:`inipath`, which is a :class:`pathlib.Path`.
:type: Optional[LEGACY_PATH]
"""
return legacy_path(str(self.inipath)) if self.inipath else None

def add_cleanup(self, func: Callable[[], None]) -> None:
"""Add a function to be called when the config object gets out of
use (usually coninciding with pytest_unconfigure)."""
Expand Down Expand Up @@ -1400,6 +1368,12 @@ def getini(self, name: str):
self._inicache[name] = val = self._getini(name)
return val

# Meant for easy monkeypatching by legacypath plugin.
# Can be inlined back (with no cover removed) once legacypath is gone.
def _getini_unknown_type(self, name: str, type: str, value: Union[str, List[str]]):
msg = f"unknown configuration type: {type}"
raise ValueError(msg, value) # pragma: no cover

def _getini(self, name: str):
try:
description, type, default = self._parser._inidict[name]
Expand Down Expand Up @@ -1432,13 +1406,7 @@ def _getini(self, name: str):
# a_line_list = ["tests", "acceptance"]
# in this case, we already have a list ready to use.
#
if type == "pathlist":
# TODO: This assert is probably not valid in all cases.
assert self.inipath is not None
dp = self.inipath.parent
input_values = shlex.split(value) if isinstance(value, str) else value
return [legacy_path(str(dp / x)) for x in input_values]
elif type == "paths":
if type == "paths":
# TODO: This assert is probably not valid in all cases.
assert self.inipath is not None
dp = self.inipath.parent
Expand All @@ -1453,9 +1421,12 @@ def _getini(self, name: str):
return value
elif type == "bool":
return _strtobool(str(value).strip())
else:
assert type in [None, "string"]
elif type == "string":
return value
elif type is None:
return value
else:
return self._getini_unknown_type(name, type, value)

def _getconftest_pathlist(
self, name: str, path: Path, rootpath: Path
Expand Down
7 changes: 0 additions & 7 deletions src/_pytest/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@
from _pytest.compat import getimfunc
from _pytest.compat import getlocation
from _pytest.compat import is_generator
from _pytest.compat import LEGACY_PATH
from _pytest.compat import legacy_path
from _pytest.compat import NOTSET
from _pytest.compat import safe_getattr
from _pytest.config import _PluggyPlugin
Expand Down Expand Up @@ -528,11 +526,6 @@ def module(self):
raise AttributeError(f"module not available in {self.scope}-scoped context")
return self._pyfuncitem.getparent(_pytest.python.Module).obj

@property
def fspath(self) -> LEGACY_PATH:
"""(deprecated) The file system path of the test module which collected this test."""
return legacy_path(self.path)

@property
def path(self) -> Path:
if self.scope not in ("function", "class", "module", "package"):
Expand Down

0 comments on commit a53abe9

Please sign in to comment.