fixup: correct rebase mistakes, to be squashed

This commit is contained in:
Ronny Pfannschmidt 2023-03-17 09:58:27 +01:00
parent dfde2c6c34
commit 02ad46a5a4
2 changed files with 5 additions and 11 deletions

View File

@ -94,21 +94,15 @@ 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:
def __str__(self: CodeLocation) -> str:
"""Python 3.6.0 hack for NamedTuple __str__"""
return f"{self.path}:{self.lineno}"
setattr(CodeLocation, "__str__", CodeLocation__str__)
def getlocation(
function, *, relative_to: Path | None, allow_escape: bool
) -> CodeLocation:

View File

@ -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