[py-svn] pytest commit e49e10c37aa0: refine initialization and collection reporting, introduce a progress bar

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Mon Nov 22 12:06:39 CET 2010


# HG changeset patch -- Bitbucket.org
# Project pytest
# URL http://bitbucket.org/hpk42/pytest/overview
# User holger krekel <holger at merlinux.eu>
# Date 1290423596 -3600
# Node ID e49e10c37aa055752e225557de5df1692b1c1cc0
# Parent  ce993aec28cc55b8edb513b4390397ff4508b1a2
refine initialization and collection reporting, introduce a progress bar

--- 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,))

--- 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*",

--- a/testing/test_skipping.py
+++ b/testing/test_skipping.py
@@ -414,8 +414,6 @@ def test_skipped_reasons_functional(test
     )
     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

--- 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()

--- 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):

--- 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. """



More information about the pytest-commit mailing list