refine initialization and collection reporting, introduce a progress bar
This commit is contained in:
parent
bc42cf8ffb
commit
0357d3afda
|
@ -405,14 +405,13 @@ def getcfg(args, inibasenames):
|
|||
args = [py.path.local()]
|
||||
for arg in args:
|
||||
arg = py.path.local(arg)
|
||||
if arg.check():
|
||||
for base in arg.parts(reverse=True):
|
||||
for inibasename in inibasenames:
|
||||
p = base.join(inibasename)
|
||||
if p.check():
|
||||
iniconfig = py.iniconfig.IniConfig(p)
|
||||
if 'pytest' in iniconfig.sections:
|
||||
return iniconfig['pytest']
|
||||
for base in arg.parts(reverse=True):
|
||||
for inibasename in inibasenames:
|
||||
p = base.join(inibasename)
|
||||
if p.check():
|
||||
iniconfig = py.iniconfig.IniConfig(p)
|
||||
if 'pytest' in iniconfig.sections:
|
||||
return iniconfig['pytest']
|
||||
return {}
|
||||
|
||||
def findupwards(current, basename):
|
||||
|
|
|
@ -218,6 +218,3 @@ def pytest_internalerror(excrepr):
|
|||
|
||||
def pytest_keyboard_interrupt(excinfo):
|
||||
""" called for keyboard interrupt. """
|
||||
|
||||
def pytest_trace(category, msg):
|
||||
""" called for debug info. """
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
This is a good source for looking at the various reporting hooks.
|
||||
"""
|
||||
import py
|
||||
import pytest, py
|
||||
import sys
|
||||
import os
|
||||
|
||||
|
@ -98,6 +98,7 @@ class TerminalReporter:
|
|||
self.showheader = self.verbosity >= 0
|
||||
self.showfspath = self.verbosity >= 0
|
||||
self.showlongtestinfo = self.verbosity > 0
|
||||
self._numcollected = 0
|
||||
|
||||
self.stats = {}
|
||||
self.curdir = py.path.local()
|
||||
|
@ -106,6 +107,7 @@ class TerminalReporter:
|
|||
self._tw = py.io.TerminalWriter(file)
|
||||
self.currentfspath = None
|
||||
self.reportchars = getreportopt(config)
|
||||
self.hasmarkup = self._tw.hasmarkup
|
||||
|
||||
def hasopt(self, char):
|
||||
char = {'xfailed': 'x', 'skipped': 's'}.get(char,char)
|
||||
|
@ -139,6 +141,10 @@ class TerminalReporter:
|
|||
self.ensure_newline()
|
||||
self._tw.line(line, **markup)
|
||||
|
||||
def rewrite(self, line, **markup):
|
||||
line = str(line)
|
||||
self._tw.write("\r" + line, **markup)
|
||||
|
||||
def write_sep(self, sep, title=None, **markup):
|
||||
self.ensure_newline()
|
||||
self._tw.sep(sep, title, **markup)
|
||||
|
@ -207,14 +213,42 @@ class TerminalReporter:
|
|||
self._tw.write(" " + line)
|
||||
self.currentfspath = -2
|
||||
|
||||
def pytest_collection(self):
|
||||
if not self.hasmarkup:
|
||||
self.write_line("collecting ...", bold=True)
|
||||
|
||||
def pytest_collectreport(self, report):
|
||||
if not report.passed:
|
||||
if report.failed:
|
||||
self.stats.setdefault("error", []).append(report)
|
||||
self.write_fspath_result(report.fspath, "E")
|
||||
elif report.skipped:
|
||||
self.stats.setdefault("skipped", []).append(report)
|
||||
self.write_fspath_result(report.fspath, "S")
|
||||
if report.failed:
|
||||
self.stats.setdefault("error", []).append(report)
|
||||
elif report.skipped:
|
||||
self.stats.setdefault("skipped", []).append(report)
|
||||
items = [x for x in report.result if isinstance(x, pytest.Item)]
|
||||
self._numcollected += len(items)
|
||||
if self.hasmarkup:
|
||||
#self.write_fspath_result(report.fspath, 'E')
|
||||
self.report_collect()
|
||||
|
||||
def report_collect(self, final=False):
|
||||
errors = len(self.stats.get('error', []))
|
||||
skipped = len(self.stats.get('skipped', []))
|
||||
if final:
|
||||
line = "collected "
|
||||
else:
|
||||
line = "collecting "
|
||||
line += str(self._numcollected) + " items"
|
||||
if errors:
|
||||
line += " / %d errors" % errors
|
||||
if skipped:
|
||||
line += " / %d skipped" % skipped
|
||||
if self.hasmarkup:
|
||||
if final:
|
||||
line += " \n"
|
||||
self.rewrite(line, bold=True)
|
||||
else:
|
||||
self.write_line(line)
|
||||
|
||||
def pytest_collection_modifyitems(self):
|
||||
self.report_collect(True)
|
||||
|
||||
def pytest_sessionstart(self, session):
|
||||
self._sessionstarttime = py.std.time.time()
|
||||
|
@ -236,8 +270,8 @@ class TerminalReporter:
|
|||
def pytest_collection_finish(self):
|
||||
if not self.showheader:
|
||||
return
|
||||
for i, testarg in enumerate(self.config.args):
|
||||
self.write_line("test path %d: %s" %(i+1, testarg))
|
||||
#for i, testarg in enumerate(self.config.args):
|
||||
# self.write_line("test path %d: %s" %(i+1, testarg))
|
||||
|
||||
def pytest_sessionfinish(self, exitstatus, __multicall__):
|
||||
__multicall__.execute()
|
||||
|
|
|
@ -7,4 +7,4 @@ def pytest_runtest_setup(item):
|
|||
return
|
||||
mod = item.getparent(pytest.Module).obj
|
||||
if hasattr(mod, 'hello'):
|
||||
py.builtin.print_("mod.hello", mod.hello)
|
||||
print ("mod.hello %r" % (mod.hello,))
|
||||
|
|
|
@ -414,8 +414,6 @@ def test_skipped_reasons_functional(testdir):
|
|||
)
|
||||
result = testdir.runpytest('--report=skipped')
|
||||
result.stdout.fnmatch_lines([
|
||||
"*test_two.py S",
|
||||
"*test_one.py ss",
|
||||
"*SKIP*3*conftest.py:3: test",
|
||||
])
|
||||
assert result.ret == 0
|
||||
|
|
|
@ -536,7 +536,6 @@ class TestGenericReporting:
|
|||
p = testdir.makepyfile("import xyz\n")
|
||||
result = testdir.runpytest(*option.args)
|
||||
result.stdout.fnmatch_lines([
|
||||
"*test_collect_fail.py E*",
|
||||
"> import xyz",
|
||||
"E ImportError: No module named xyz",
|
||||
"*1 error*",
|
||||
|
|
Loading…
Reference in New Issue