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