From d979f82fb0f7a05a41d8afb45e2448665ab20a01 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Sat, 16 Oct 2021 10:54:28 +0300 Subject: [PATCH] Move TerminalReporter.stardir to legacypath plugin --- src/_pytest/legacypath.py | 16 ++++++++++++++++ src/_pytest/terminal.py | 12 ------------ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/_pytest/legacypath.py b/src/_pytest/legacypath.py index 08d668f46..cac22927c 100644 --- a/src/_pytest/legacypath.py +++ b/src/_pytest/legacypath.py @@ -14,6 +14,7 @@ from _pytest.compat import final from _pytest.compat import LEGACY_PATH from _pytest.compat import legacy_path from _pytest.deprecated import check_ispytest +from _pytest.terminal import TerminalReporter if TYPE_CHECKING: from typing_extensions import Final @@ -320,6 +321,16 @@ def FixtureRequest_fspath(self: pytest.FixtureRequest) -> LEGACY_PATH: return legacy_path(self.path) +def TerminalReporter_startdir(self: TerminalReporter) -> LEGACY_PATH: + """The directory 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) @@ -345,3 +356,8 @@ def pytest_configure(config: pytest.Config) -> None: mp.setattr( pytest.FixtureRequest, "fspath", property(FixtureRequest_fspath), raising=False ) + + # Add TerminalReporter.startdir property. + mp.setattr( + TerminalReporter, "startdir", property(TerminalReporter_startdir), raising=False + ) diff --git a/src/_pytest/terminal.py b/src/_pytest/terminal.py index 8c5be3b78..ba540eef8 100644 --- a/src/_pytest/terminal.py +++ b/src/_pytest/terminal.py @@ -37,8 +37,6 @@ from _pytest._code import ExceptionInfo from _pytest._code.code import ExceptionRepr from _pytest._io.wcwidth import wcswidth from _pytest.compat import final -from _pytest.compat import LEGACY_PATH -from _pytest.compat import legacy_path from _pytest.config import _PluggyPlugin from _pytest.config import Config from _pytest.config import ExitCode @@ -383,16 +381,6 @@ class TerminalReporter: def showlongtestinfo(self) -> bool: return self.verbosity > 0 - @property - def startdir(self) -> LEGACY_PATH: - """The directory from which pytest was invoked. - - Prefer to use ``startpath`` which is a :class:`pathlib.Path`. - - :type: LEGACY_PATH - """ - return legacy_path(self.startpath) - def hasopt(self, char: str) -> bool: char = {"xfailed": "x", "skipped": "s"}.get(char, char) return char in self.reportchars