From 02ad46a5a43bada7c787083099f1cf0c37a96ec1 Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Fri, 17 Mar 2023 09:58:27 +0100 Subject: [PATCH] fixup: correct rebase mistakes, to be squashed --- src/_pytest/compat.py | 12 +++--------- src/_pytest/python.py | 4 ++-- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/src/_pytest/compat.py b/src/_pytest/compat.py index e3737356e..26b6e95c2 100644 --- a/src/_pytest/compat.py +++ b/src/_pytest/compat.py @@ -94,19 +94,13 @@ def is_async_function(func: object) -> bool: return iscoroutinefunction(func) or inspect.isasyncgenfunction(func) -def getlocation(function, curdir: str | None = None) -> str: class CodeLocation(NamedTuple): path: Path lineno: int - -# TODO: integrate after pytest 3.6.0 has been dropped -def CodeLocation__str__(self: CodeLocation) -> str: - """Python 3.6.0 hack for NamedTuple __str__""" - return f"{self.path}:{self.lineno}" - - -setattr(CodeLocation, "__str__", CodeLocation__str__) + def __str__(self: CodeLocation) -> str: + """Python 3.6.0 hack for NamedTuple __str__""" + return f"{self.path}:{self.lineno}" def getlocation( diff --git a/src/_pytest/python.py b/src/_pytest/python.py index fdd327457..949dbd2db 100644 --- a/src/_pytest/python.py +++ b/src/_pytest/python.py @@ -1554,7 +1554,7 @@ def _ascii_escaped_by_config(val: Union[str, bytes], config: Optional[Config]) - def _pretty_fixture_path(func) -> str: cwd = Path.cwd() - loc = Path(getlocation(func, str(cwd))) + loc = Path(str(getlocation(func, relative_to=cwd, allow_escape=False))) prefix = Path("...", "_pytest") try: return str(prefix / loc.relative_to(_PYTEST_DIR)) @@ -1577,7 +1577,7 @@ def _show_fixtures_per_test(config: Config, session: Session) -> None: verbose = config.getvalue("verbose") def get_best_relpath(func): - return getlocation(func, curdir) + return getlocation(func, relative_to=curdir, allow_escape=False) def write_fixture(fixture_def: fixtures.FixtureDef[object]) -> None: argname = fixture_def.argname