Skip to content

Commit 84722a7

Browse files
committed
Move Config.{invocation_dir,rootdir,inifile} to legacypath plugin
1 parent d979f82 commit 84722a7

File tree

2 files changed

+38
-32
lines changed

2 files changed

+38
-32
lines changed

src/_pytest/config/__init__.py

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +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
5352
from _pytest.compat import legacy_path
5453
from _pytest.outcomes import fail
5554
from _pytest.outcomes import Skipped
@@ -950,17 +949,6 @@ def __init__(
950949

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

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

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

994-
@property
995-
def inifile(self) -> Optional[LEGACY_PATH]:
996-
"""The path to the :ref:`configfile <configfiles>`.
997-
998-
Prefer to use :attr:`inipath`, which is a :class:`pathlib.Path`.
999-
1000-
:type: Optional[LEGACY_PATH]
1001-
"""
1002-
return legacy_path(str(self.inipath)) if self.inipath else None
1003-
1004972
def add_cleanup(self, func: Callable[[], None]) -> None:
1005973
"""Add a function to be called when the config object gets out of
1006974
use (usually coninciding with pytest_unconfigure)."""

src/_pytest/legacypath.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,37 @@ def TerminalReporter_startdir(self: TerminalReporter) -> LEGACY_PATH:
331331
return legacy_path(self.startpath)
332332

333333

334+
def Config_invocation_dir(self: pytest.Config) -> LEGACY_PATH:
335+
"""The directory from which pytest was invoked.
336+
337+
Prefer to use :attr:`invocation_params.dir <InvocationParams.dir>`,
338+
which is a :class:`pathlib.Path`.
339+
340+
:type: LEGACY_PATH
341+
"""
342+
return legacy_path(str(self.invocation_params.dir))
343+
344+
345+
def Config_rootdir(self: pytest.Config) -> LEGACY_PATH:
346+
"""The path to the :ref:`rootdir <rootdir>`.
347+
348+
Prefer to use :attr:`rootpath`, which is a :class:`pathlib.Path`.
349+
350+
:type: LEGACY_PATH
351+
"""
352+
return legacy_path(str(self.rootpath))
353+
354+
355+
def Config_inifile(self: pytest.Config) -> Optional[LEGACY_PATH]:
356+
"""The path to the :ref:`configfile <configfiles>`.
357+
358+
Prefer to use :attr:`inipath`, which is a :class:`pathlib.Path`.
359+
360+
:type: Optional[LEGACY_PATH]
361+
"""
362+
return legacy_path(str(self.inipath)) if self.inipath else None
363+
364+
334365
def pytest_configure(config: pytest.Config) -> None:
335366
mp = pytest.MonkeyPatch()
336367
config.add_cleanup(mp.undo)
@@ -361,3 +392,10 @@ def pytest_configure(config: pytest.Config) -> None:
361392
mp.setattr(
362393
TerminalReporter, "startdir", property(TerminalReporter_startdir), raising=False
363394
)
395+
396+
# Add Config.{invocation_dir,rootdir,inifile} properties.
397+
mp.setattr(
398+
pytest.Config, "invocation_dir", property(Config_invocation_dir), raising=False
399+
)
400+
mp.setattr(pytest.Config, "rootdir", property(Config_rootdir), raising=False)
401+
mp.setattr(pytest.Config, "inifile", property(Config_inifile), raising=False)

0 commit comments

Comments
 (0)