From 0357d3afdad59d4b208c9983468bf5d48c5f92e2 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Mon, 22 Nov 2010 11:59:56 +0100 Subject: [PATCH] refine initialization and collection reporting, introduce a progress bar --- _pytest/config.py | 15 +++--- _pytest/hookspec.py | 3 -- _pytest/terminal.py | 54 +++++++++++++++---- .../global_testmodule_config/conftest.py | 2 +- testing/test_skipping.py | 2 - testing/test_terminal.py | 1 - 6 files changed, 52 insertions(+), 25 deletions(-) diff --git a/_pytest/config.py b/_pytest/config.py index ff2d0478d..95f9627d0 100644 --- a/_pytest/config.py +++ b/_pytest/config.py @@ -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): diff --git a/_pytest/hookspec.py b/_pytest/hookspec.py index d4bf9f165..bc6d5405e 100644 --- a/_pytest/hookspec.py +++ b/_pytest/hookspec.py @@ -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. """ diff --git a/_pytest/terminal.py b/_pytest/terminal.py index 1fca30968..05b07091f 100644 --- a/_pytest/terminal.py +++ b/_pytest/terminal.py @@ -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() diff --git a/doc/example/assertion/global_testmodule_config/conftest.py b/doc/example/assertion/global_testmodule_config/conftest.py index c7bb60aa1..71e8c54be 100644 --- a/doc/example/assertion/global_testmodule_config/conftest.py +++ b/doc/example/assertion/global_testmodule_config/conftest.py @@ -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,)) diff --git a/testing/test_skipping.py b/testing/test_skipping.py index 34c64d6de..1f2a445d9 100644 --- a/testing/test_skipping.py +++ b/testing/test_skipping.py @@ -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 diff --git a/testing/test_terminal.py b/testing/test_terminal.py index bce1d101c..bfebfe696 100644 --- a/testing/test_terminal.py +++ b/testing/test_terminal.py @@ -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*",