some minor tweaks to terminal.py

This commit is contained in:
symonk 2021-10-27 14:07:05 +01:00
parent b7fc0003fd
commit 24946128af
1 changed files with 13 additions and 16 deletions

View File

@ -231,7 +231,7 @@ def pytest_configure(config: Config) -> None:
config.pluginmanager.register(reporter, "terminalreporter") config.pluginmanager.register(reporter, "terminalreporter")
if config.option.debug or config.option.traceconfig: if config.option.debug or config.option.traceconfig:
def mywriter(tags, args): def mywriter(args):
msg = " ".join(map(str, args)) msg = " ".join(map(str, args))
reporter.write_line("[traceconfig] " + msg) reporter.write_line("[traceconfig] " + msg)
@ -511,7 +511,9 @@ class TerminalReporter:
# Ensure that the path is printed before the # Ensure that the path is printed before the
# 1st test of a module starts running. # 1st test of a module starts running.
if self.showlongtestinfo: if self.showlongtestinfo:
line = self._locationline(nodeid, *location) line = self._locationline(
nodeid=nodeid, fspath=location[0], domain=location[-1]
)
self.write_ensure_prefix(line, "") self.write_ensure_prefix(line, "")
self.flush() self.flush()
elif self.showfspath: elif self.showfspath:
@ -550,7 +552,9 @@ class TerminalReporter:
self._tw.write(letter, **markup) self._tw.write(letter, **markup)
else: else:
self._progress_nodeids_reported.add(rep.nodeid) self._progress_nodeids_reported.add(rep.nodeid)
line = self._locationline(rep.nodeid, *rep.location) line = self._locationline(
nodeid=rep.nodeid, fspath=rep.location[0], domain=rep.location[-1]
)
if not running_xdist: if not running_xdist:
self.write_ensure_prefix(line, word, **markup) self.write_ensure_prefix(line, word, **markup)
if rep.skipped or hasattr(report, "wasxfail"): if rep.skipped or hasattr(report, "wasxfail"):
@ -862,8 +866,8 @@ class TerminalReporter:
yellow=True, yellow=True,
) )
def _locationline(self, nodeid, fspath, lineno, domain): def _locationline(self, nodeid: str, fspath: str, domain: str) -> str:
def mkrel(nodeid): def mkrel(nodeid) -> str:
line = self.config.cwd_relative_nodeid(nodeid) line = self.config.cwd_relative_nodeid(nodeid)
if domain and line.endswith(domain): if domain and line.endswith(domain):
line = line[: -len(domain)] line = line[: -len(domain)]
@ -879,16 +883,13 @@ class TerminalReporter:
if self.verbosity >= 2 and nodeid.split("::")[0] != fspath.replace( if self.verbosity >= 2 and nodeid.split("::")[0] != fspath.replace(
"\\", nodes.SEP "\\", nodes.SEP
): ):
res += " <- " + bestrelpath(self.startpath, fspath) res += " <- " + bestrelpath(self.startpath, Path(fspath))
else: else:
res = "[location]" res = "[location]"
return res + " " return res + " "
def _getfailureheadline(self, rep): def _getfailureheadline(self, rep) -> str:
head_line = rep.head_line return rep.head_line or "test session"
if head_line:
return head_line
return "test session" # XXX?
def _getcrashline(self, rep): def _getcrashline(self, rep):
try: try:
@ -903,11 +904,7 @@ class TerminalReporter:
# Summaries for sessionfinish. # Summaries for sessionfinish.
# #
def getreports(self, name: str): def getreports(self, name: str):
values = [] return [x for x in self.stats.get(name, ()) if not hasattr(x, "_pdbshown")]
for x in self.stats.get(name, []):
if not hasattr(x, "_pdbshown"):
values.append(x)
return values
def summary_warnings(self) -> None: def summary_warnings(self) -> None:
if self.hasopt("w"): if self.hasopt("w"):