Skip to content

Commit a53abe9

Browse files
authored
Merge pull request #9208 from bluetech/legacypath-plugin
Add legacypath plugin, move py.path stuff there
2 parents e1b3c2d + e6eac28 commit a53abe9

18 files changed

+647
-448
lines changed

doc/en/conf.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,3 +460,7 @@ def patched_is_final(self, decorators: List[ast.expr]) -> bool:
460460
)
461461

462462
sphinx.pycode.parser.VariableCommentPicker.is_final = patched_is_final
463+
464+
# legacypath.py monkey-patches pytest.Testdir in. Import the file so
465+
# that autodoc can discover references to it.
466+
import _pytest.legacypath # noqa: F401

doc/en/reference/reference.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ tmpdir
638638

639639
:ref:`tmpdir and tmpdir_factory`
640640

641-
.. autofunction:: _pytest.tmpdir.tmpdir()
641+
.. autofunction:: _pytest.legacypath.LegacyTmpdirPlugin.tmpdir()
642642
:no-auto-options:
643643

644644

src/_pytest/cacheprovider.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
from _pytest import nodes
2121
from _pytest._io import TerminalWriter
2222
from _pytest.compat import final
23-
from _pytest.compat import LEGACY_PATH
24-
from _pytest.compat import legacy_path
2523
from _pytest.config import Config
2624
from _pytest.config import ExitCode
2725
from _pytest.config import hookimpl
@@ -142,13 +140,6 @@ def mkdir(self, name: str) -> Path:
142140
res.mkdir(exist_ok=True, parents=True)
143141
return res
144142

145-
def makedir(self, name: str) -> LEGACY_PATH:
146-
"""Return a directory path object with the given name.
147-
148-
Same as :func:`mkdir`, but returns a legacy py path instance.
149-
"""
150-
return legacy_path(self.mkdir(name))
151-
152143
def _getvaluepath(self, key: str) -> Path:
153144
return self._cachedir.joinpath(self._CACHE_PREFIX_VALUES, Path(key))
154145

src/_pytest/config/__init__.py

Lines changed: 13 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@
4949
from _pytest._io import TerminalWriter
5050
from _pytest.compat import final
5151
from _pytest.compat import importlib_metadata
52-
from _pytest.compat import LEGACY_PATH
53-
from _pytest.compat import legacy_path
5452
from _pytest.outcomes import fail
5553
from _pytest.outcomes import Skipped
5654
from _pytest.pathlib import absolutepath
@@ -240,6 +238,7 @@ def directory_arg(path: str, optname: str) -> str:
240238
"unittest",
241239
"capture",
242240
"skipping",
241+
"legacypath",
243242
"tmpdir",
244243
"monkeypatch",
245244
"recwarn",
@@ -949,17 +948,6 @@ def __init__(
949948

950949
self.cache: Optional[Cache] = None
951950

952-
@property
953-
def invocation_dir(self) -> LEGACY_PATH:
954-
"""The directory from which pytest was invoked.
955-
956-
Prefer to use :attr:`invocation_params.dir <InvocationParams.dir>`,
957-
which is a :class:`pathlib.Path`.
958-
959-
:type: LEGACY_PATH
960-
"""
961-
return legacy_path(str(self.invocation_params.dir))
962-
963951
@property
964952
def rootpath(self) -> Path:
965953
"""The path to the :ref:`rootdir <rootdir>`.
@@ -970,16 +958,6 @@ def rootpath(self) -> Path:
970958
"""
971959
return self._rootpath
972960

973-
@property
974-
def rootdir(self) -> LEGACY_PATH:
975-
"""The path to the :ref:`rootdir <rootdir>`.
976-
977-
Prefer to use :attr:`rootpath`, which is a :class:`pathlib.Path`.
978-
979-
:type: LEGACY_PATH
980-
"""
981-
return legacy_path(str(self.rootpath))
982-
983961
@property
984962
def inipath(self) -> Optional[Path]:
985963
"""The path to the :ref:`configfile <configfiles>`.
@@ -990,16 +968,6 @@ def inipath(self) -> Optional[Path]:
990968
"""
991969
return self._inipath
992970

993-
@property
994-
def inifile(self) -> Optional[LEGACY_PATH]:
995-
"""The path to the :ref:`configfile <configfiles>`.
996-
997-
Prefer to use :attr:`inipath`, which is a :class:`pathlib.Path`.
998-
999-
:type: Optional[LEGACY_PATH]
1000-
"""
1001-
return legacy_path(str(self.inipath)) if self.inipath else None
1002-
1003971
def add_cleanup(self, func: Callable[[], None]) -> None:
1004972
"""Add a function to be called when the config object gets out of
1005973
use (usually coninciding with pytest_unconfigure)."""
@@ -1400,6 +1368,12 @@ def getini(self, name: str):
14001368
self._inicache[name] = val = self._getini(name)
14011369
return val
14021370

1371+
# Meant for easy monkeypatching by legacypath plugin.
1372+
# Can be inlined back (with no cover removed) once legacypath is gone.
1373+
def _getini_unknown_type(self, name: str, type: str, value: Union[str, List[str]]):
1374+
msg = f"unknown configuration type: {type}"
1375+
raise ValueError(msg, value) # pragma: no cover
1376+
14031377
def _getini(self, name: str):
14041378
try:
14051379
description, type, default = self._parser._inidict[name]
@@ -1432,13 +1406,7 @@ def _getini(self, name: str):
14321406
# a_line_list = ["tests", "acceptance"]
14331407
# in this case, we already have a list ready to use.
14341408
#
1435-
if type == "pathlist":
1436-
# TODO: This assert is probably not valid in all cases.
1437-
assert self.inipath is not None
1438-
dp = self.inipath.parent
1439-
input_values = shlex.split(value) if isinstance(value, str) else value
1440-
return [legacy_path(str(dp / x)) for x in input_values]
1441-
elif type == "paths":
1409+
if type == "paths":
14421410
# TODO: This assert is probably not valid in all cases.
14431411
assert self.inipath is not None
14441412
dp = self.inipath.parent
@@ -1453,9 +1421,12 @@ def _getini(self, name: str):
14531421
return value
14541422
elif type == "bool":
14551423
return _strtobool(str(value).strip())
1456-
else:
1457-
assert type in [None, "string"]
1424+
elif type == "string":
1425+
return value
1426+
elif type is None:
14581427
return value
1428+
else:
1429+
return self._getini_unknown_type(name, type, value)
14591430

14601431
def _getconftest_pathlist(
14611432
self, name: str, path: Path, rootpath: Path

src/_pytest/fixtures.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@
4646
from _pytest.compat import getimfunc
4747
from _pytest.compat import getlocation
4848
from _pytest.compat import is_generator
49-
from _pytest.compat import LEGACY_PATH
50-
from _pytest.compat import legacy_path
5149
from _pytest.compat import NOTSET
5250
from _pytest.compat import safe_getattr
5351
from _pytest.config import _PluggyPlugin
@@ -528,11 +526,6 @@ def module(self):
528526
raise AttributeError(f"module not available in {self.scope}-scoped context")
529527
return self._pyfuncitem.getparent(_pytest.python.Module).obj
530528

531-
@property
532-
def fspath(self) -> LEGACY_PATH:
533-
"""(deprecated) The file system path of the test module which collected this test."""
534-
return legacy_path(self.path)
535-
536529
@property
537530
def path(self) -> Path:
538531
if self.scope not in ("function", "class", "module", "package"):

0 commit comments

Comments
 (0)