Skip to content

Commit d979f82

Browse files
committed
Move TerminalReporter.stardir to legacypath plugin
1 parent 7c00113 commit d979f82

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

src/_pytest/legacypath.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from _pytest.compat import LEGACY_PATH
1515
from _pytest.compat import legacy_path
1616
from _pytest.deprecated import check_ispytest
17+
from _pytest.terminal import TerminalReporter
1718

1819
if TYPE_CHECKING:
1920
from typing_extensions import Final
@@ -320,6 +321,16 @@ def FixtureRequest_fspath(self: pytest.FixtureRequest) -> LEGACY_PATH:
320321
return legacy_path(self.path)
321322

322323

324+
def TerminalReporter_startdir(self: TerminalReporter) -> LEGACY_PATH:
325+
"""The directory from which pytest was invoked.
326+
327+
Prefer to use ``startpath`` which is a :class:`pathlib.Path`.
328+
329+
:type: LEGACY_PATH
330+
"""
331+
return legacy_path(self.startpath)
332+
333+
323334
def pytest_configure(config: pytest.Config) -> None:
324335
mp = pytest.MonkeyPatch()
325336
config.add_cleanup(mp.undo)
@@ -345,3 +356,8 @@ def pytest_configure(config: pytest.Config) -> None:
345356
mp.setattr(
346357
pytest.FixtureRequest, "fspath", property(FixtureRequest_fspath), raising=False
347358
)
359+
360+
# Add TerminalReporter.startdir property.
361+
mp.setattr(
362+
TerminalReporter, "startdir", property(TerminalReporter_startdir), raising=False
363+
)

src/_pytest/terminal.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@
3737
from _pytest._code.code import ExceptionRepr
3838
from _pytest._io.wcwidth import wcswidth
3939
from _pytest.compat import final
40-
from _pytest.compat import LEGACY_PATH
41-
from _pytest.compat import legacy_path
4240
from _pytest.config import _PluggyPlugin
4341
from _pytest.config import Config
4442
from _pytest.config import ExitCode
@@ -383,16 +381,6 @@ def showfspath(self, value: Optional[bool]) -> None:
383381
def showlongtestinfo(self) -> bool:
384382
return self.verbosity > 0
385383

386-
@property
387-
def startdir(self) -> LEGACY_PATH:
388-
"""The directory from which pytest was invoked.
389-
390-
Prefer to use ``startpath`` which is a :class:`pathlib.Path`.
391-
392-
:type: LEGACY_PATH
393-
"""
394-
return legacy_path(self.startpath)
395-
396384
def hasopt(self, char: str) -> bool:
397385
char = {"xfailed": "x", "skipped": "s"}.get(char, char)
398386
return char in self.reportchars

0 commit comments

Comments
 (0)