Skip to content

Commit c3511c2

Browse files
committed
Move Session.startdir to legacypath plugin
1 parent 19fdf0e commit c3511c2

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

src/_pytest/legacypath.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,16 @@ def Config_inifile(self: pytest.Config) -> Optional[LEGACY_PATH]:
362362
return legacy_path(str(self.inipath)) if self.inipath else None
363363

364364

365+
def Session_stardir(self: pytest.Session) -> LEGACY_PATH:
366+
"""The path from which pytest was invoked.
367+
368+
Prefer to use ``startpath`` which is a :class:`pathlib.Path`.
369+
370+
:type: LEGACY_PATH
371+
"""
372+
return legacy_path(self.startpath)
373+
374+
365375
def pytest_configure(config: pytest.Config) -> None:
366376
mp = pytest.MonkeyPatch()
367377
config.add_cleanup(mp.undo)
@@ -399,3 +409,6 @@ def pytest_configure(config: pytest.Config) -> None:
399409
)
400410
mp.setattr(pytest.Config, "rootdir", property(Config_rootdir), raising=False)
401411
mp.setattr(pytest.Config, "inifile", property(Config_inifile), raising=False)
412+
413+
# Add Session.startdir property.
414+
mp.setattr(pytest.Session, "startdir", property(Session_stardir), raising=False)

src/_pytest/main.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
import _pytest._code
2626
from _pytest import nodes
2727
from _pytest.compat import final
28-
from _pytest.compat import LEGACY_PATH
29-
from _pytest.compat import legacy_path
3028
from _pytest.config import Config
3129
from _pytest.config import directory_arg
3230
from _pytest.config import ExitCode
@@ -504,16 +502,6 @@ def startpath(self) -> Path:
504502
"""
505503
return self.config.invocation_params.dir
506504

507-
@property
508-
def stardir(self) -> LEGACY_PATH:
509-
"""The path from which pytest was invoked.
510-
511-
Prefer to use ``startpath`` which is a :class:`pathlib.Path`.
512-
513-
:type: LEGACY_PATH
514-
"""
515-
return legacy_path(self.startpath)
516-
517505
def _node_location_to_relpath(self, node_path: Path) -> str:
518506
# bestrelpath is a quite slow function.
519507
return self._bestrelpathcache[node_path]

0 commit comments

Comments
 (0)