From d9ca55c648266afff0fb3820704d69289faa10d2 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Sat, 16 Oct 2021 11:01:18 +0300 Subject: [PATCH] Move Session.startdir to legacypath plugin --- src/_pytest/legacypath.py | 13 +++++++++++++ src/_pytest/main.py | 12 ------------ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/_pytest/legacypath.py b/src/_pytest/legacypath.py index 78afeb7d1..3fca65b25 100644 --- a/src/_pytest/legacypath.py +++ b/src/_pytest/legacypath.py @@ -362,6 +362,16 @@ def Config_inifile(self: pytest.Config) -> Optional[LEGACY_PATH]: return legacy_path(str(self.inipath)) if self.inipath else None +def Session_stardir(self: pytest.Session) -> LEGACY_PATH: + """The path from which pytest was invoked. + + Prefer to use ``startpath`` which is a :class:`pathlib.Path`. + + :type: LEGACY_PATH + """ + return legacy_path(self.startpath) + + def pytest_configure(config: pytest.Config) -> None: mp = pytest.MonkeyPatch() config.add_cleanup(mp.undo) @@ -399,3 +409,6 @@ def pytest_configure(config: pytest.Config) -> None: ) mp.setattr(pytest.Config, "rootdir", property(Config_rootdir), raising=False) mp.setattr(pytest.Config, "inifile", property(Config_inifile), raising=False) + + # Add Session.startdir property. + mp.setattr(pytest.Session, "startdir", property(Session_stardir), raising=False) diff --git a/src/_pytest/main.py b/src/_pytest/main.py index c48222409..b10794e57 100644 --- a/src/_pytest/main.py +++ b/src/_pytest/main.py @@ -25,8 +25,6 @@ import attr import _pytest._code from _pytest import nodes 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 directory_arg from _pytest.config import ExitCode @@ -504,16 +502,6 @@ class Session(nodes.FSCollector): """ return self.config.invocation_params.dir - @property - def stardir(self) -> LEGACY_PATH: - """The path from which pytest was invoked. - - Prefer to use ``startpath`` which is a :class:`pathlib.Path`. - - :type: LEGACY_PATH - """ - return legacy_path(self.startpath) - def _node_location_to_relpath(self, node_path: Path) -> str: # bestrelpath is a quite slow function. return self._bestrelpathcache[node_path]