Use correct input arg type for _bestrelpath
This commit is contained in:
parent
f695e18ddb
commit
6847992ce8
1
AUTHORS
1
AUTHORS
|
@ -138,6 +138,7 @@ Grigorii Eremeev (budulianin)
|
|||
Guido Wesdorp
|
||||
Guoqiang Zhang
|
||||
Harald Armin Massa
|
||||
Harshna
|
||||
Henk-Jaap Wagenaar
|
||||
Holger Kohr
|
||||
Hugo van Kemenade
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
TerminalReporter's ``_locationline()`` will now pass the correct type of input arg to ``_pytest.pathlib.bestrelpath``. Previously it was passing in ``str`` which raised an exception.
|
|
@ -862,8 +862,10 @@ class TerminalReporter:
|
|||
yellow=True,
|
||||
)
|
||||
|
||||
def _locationline(self, nodeid, fspath, lineno, domain):
|
||||
def mkrel(nodeid):
|
||||
def _locationline(
|
||||
self, nodeid: str, fspath: str, lineno: Optional[int], domain: str
|
||||
) -> str:
|
||||
def mkrel(nodeid) -> str:
|
||||
line = self.config.cwd_relative_nodeid(nodeid)
|
||||
if domain and line.endswith(domain):
|
||||
line = line[: -len(domain)]
|
||||
|
@ -873,13 +875,13 @@ class TerminalReporter:
|
|||
return line
|
||||
|
||||
# collect_fspath comes from testid which has a "/"-normalized path.
|
||||
|
||||
if fspath:
|
||||
res = mkrel(nodeid)
|
||||
if self.verbosity >= 2 and nodeid.split("::")[0] != fspath.replace(
|
||||
"\\", nodes.SEP
|
||||
):
|
||||
res += " <- " + bestrelpath(self.startpath, fspath)
|
||||
fs_path = Path(fspath)
|
||||
res += " <- " + bestrelpath(self.startpath, fs_path)
|
||||
else:
|
||||
res = "[location]"
|
||||
return res + " "
|
||||
|
|
|
@ -1165,3 +1165,16 @@ def test_log_file_cli_subdirectories_are_successfully_created(
|
|||
result = pytester.runpytest("--log-file=foo/bar/logf.log")
|
||||
assert "logf.log" in os.listdir(expected)
|
||||
assert result.ret == ExitCode.OK
|
||||
|
||||
|
||||
def test_locationline_returns_best_relative_location(pytester: Pytester) -> None:
|
||||
item = pytester.getitem("def test_func(): pass")
|
||||
item.config.option.verbose = 2
|
||||
|
||||
tr = TerminalReporter(item.config)
|
||||
fspath = f"{pytester.path}/unique/path"
|
||||
nodeid = "nodeid::test"
|
||||
result = tr._locationline(nodeid, fspath, 1, "domain")
|
||||
|
||||
expected_result = f"{nodeid} <- unique/path "
|
||||
assert result == expected_result
|
||||
|
|
Loading…
Reference in New Issue