Move TerminalReporter.stardir to legacypath plugin
This commit is contained in:
parent
7c0011374c
commit
d979f82fb0
|
@ -14,6 +14,7 @@ from _pytest.compat import final
|
||||||
from _pytest.compat import LEGACY_PATH
|
from _pytest.compat import LEGACY_PATH
|
||||||
from _pytest.compat import legacy_path
|
from _pytest.compat import legacy_path
|
||||||
from _pytest.deprecated import check_ispytest
|
from _pytest.deprecated import check_ispytest
|
||||||
|
from _pytest.terminal import TerminalReporter
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from typing_extensions import Final
|
from typing_extensions import Final
|
||||||
|
@ -320,6 +321,16 @@ def FixtureRequest_fspath(self: pytest.FixtureRequest) -> LEGACY_PATH:
|
||||||
return legacy_path(self.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:
|
def pytest_configure(config: pytest.Config) -> None:
|
||||||
mp = pytest.MonkeyPatch()
|
mp = pytest.MonkeyPatch()
|
||||||
config.add_cleanup(mp.undo)
|
config.add_cleanup(mp.undo)
|
||||||
|
@ -345,3 +356,8 @@ def pytest_configure(config: pytest.Config) -> None:
|
||||||
mp.setattr(
|
mp.setattr(
|
||||||
pytest.FixtureRequest, "fspath", property(FixtureRequest_fspath), raising=False
|
pytest.FixtureRequest, "fspath", property(FixtureRequest_fspath), raising=False
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Add TerminalReporter.startdir property.
|
||||||
|
mp.setattr(
|
||||||
|
TerminalReporter, "startdir", property(TerminalReporter_startdir), raising=False
|
||||||
|
)
|
||||||
|
|
|
@ -37,8 +37,6 @@ from _pytest._code import ExceptionInfo
|
||||||
from _pytest._code.code import ExceptionRepr
|
from _pytest._code.code import ExceptionRepr
|
||||||
from _pytest._io.wcwidth import wcswidth
|
from _pytest._io.wcwidth import wcswidth
|
||||||
from _pytest.compat import final
|
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 _PluggyPlugin
|
||||||
from _pytest.config import Config
|
from _pytest.config import Config
|
||||||
from _pytest.config import ExitCode
|
from _pytest.config import ExitCode
|
||||||
|
@ -383,16 +381,6 @@ class TerminalReporter:
|
||||||
def showlongtestinfo(self) -> bool:
|
def showlongtestinfo(self) -> bool:
|
||||||
return self.verbosity > 0
|
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:
|
def hasopt(self, char: str) -> bool:
|
||||||
char = {"xfailed": "x", "skipped": "s"}.get(char, char)
|
char = {"xfailed": "x", "skipped": "s"}.get(char, char)
|
||||||
return char in self.reportchars
|
return char in self.reportchars
|
||||||
|
|
Loading…
Reference in New Issue