[py-svn] r56688 - in py/branch/event/py/test2: . testing

hpk at codespeak.net hpk at codespeak.net
Sun Jul 20 17:49:15 CEST 2008


Author: hpk
Date: Sun Jul 20 17:49:13 2008
New Revision: 56688

Modified:
   py/branch/event/py/test2/item.py
   py/branch/event/py/test2/present.py
   py/branch/event/py/test2/repevent.py
   py/branch/event/py/test2/runner.py
   py/branch/event/py/test2/testing/test_runner.py
Log:
implement setupfailure recognition and specialized reporting


Modified: py/branch/event/py/test2/item.py
==============================================================================
--- py/branch/event/py/test2/item.py	(original)
+++ py/branch/event/py/test2/item.py	Sun Jul 20 17:49:13 2008
@@ -17,8 +17,8 @@
      
     def prepare(self, colitem): 
         """ setup objects along the collector chain to the test-method
-            Teardown any unneccessary previously setup objects. 
-        """
+            Teardown any unneccessary previously setup objects."""
+
         needed_collectors = colitem.listchain() 
         while self.stack: 
             if self.stack == needed_collectors[:len(self.stack)]: 
@@ -66,9 +66,7 @@
 
     def repr_run(self, runnerinfo):
         """ return a textual representation of run info. """ 
-        p = present.PythonFunctionPresenter(self._config, self) 
-        p.repr_run(runnerinfo)
-        return p.out.stringio.getvalue()
+        return present.python_repr_run(self, runnerinfo)
 
     def repr_path(self):
         from py.__.test2.rep.reporter import getrelpath, getmodpath

Modified: py/branch/event/py/test2/present.py
==============================================================================
--- py/branch/event/py/test2/present.py	(original)
+++ py/branch/event/py/test2/present.py	Sun Jul 20 17:49:13 2008
@@ -16,10 +16,12 @@
             style=config.option.tbstyle,
         )
 
-    def header(self):
+    def header(self, title=None):
         item = self._item
-        modpath = getmodpath(item)
-        self.out.sep("_", "entrypoint: %s" %(modpath))
+        if title is None:
+            modpath = getmodpath(item)
+            title = "entrypoint: %s" % modpath
+        self.out.sep("_", title)
         self.out.line("")
         if item.name[-1] == "]":   # print extra info for generated tests
             if not self._config.option.fulltrace: 
@@ -29,9 +31,9 @@
                 self.out.line(line)
 
 
-    def repr_run(self, runnerinfo):
+    def repr_run(self, runnerinfo, title=None):
         excinfo = runnerinfo.excinfo
-        self.header()
+        self.header(title)
         if excinfo:
             excinfo.traceback = self._item.prunetraceback(excinfo.traceback)
             self.repr_tb(excinfo)
@@ -40,3 +42,8 @@
                 self.out.sep("- ", "%s, len=%d" %(name, len(value)))
                 self.out.line(value.rstrip())
         self.repr_sep("_")
+
+def python_repr_run(item, runnerinfo, title=None):
+    p = PythonFunctionPresenter(item._config, item)
+    p.repr_run(runnerinfo, title=title)
+    return p.out.stringio.getvalue()

Modified: py/branch/event/py/test2/repevent.py
==============================================================================
--- py/branch/event/py/test2/repevent.py	(original)
+++ py/branch/event/py/test2/repevent.py	Sun Jul 20 17:49:13 2008
@@ -58,7 +58,8 @@
 
 class ItemTestReport(BaseEvent): 
     passed = property(lambda self: self.outcome == "passed")
-    failed = property(lambda self: self.outcome == "failed")
+    failed = property(lambda self: self.outcome == "failed" or self.outcome == "setupfailed")
+    setupfailed = property(lambda self: self.outcome == "setupfailed")
     skipped = property(lambda self: self.outcome == "skipped")
 
     @classmethod
@@ -84,7 +85,7 @@
         
     def __init__(self, trail, outcome, repr_run, repr_path, outerr=None):
         self.trail = trail 
-        assert outcome in ("passed", "failed", "skipped") 
+        assert outcome in ("passed", "failed", "skipped", "setupfailed") 
         self.outcome = outcome
         self.repr_run = repr_run
         self.repr_path = repr_path

Modified: py/branch/event/py/test2/runner.py
==============================================================================
--- py/branch/event/py/test2/runner.py	(original)
+++ py/branch/event/py/test2/runner.py	Sun Jul 20 17:49:13 2008
@@ -8,20 +8,13 @@
 from py.__.test2.outcome import Skipped
 from py.__.test.outcome import Skipped as Skipped2
 import py.__.test2.custompdb
+from py.__.test2 import present
 
 class RunnerInfo:
     """ info on test runs. """
     def __init__(self, excinfo, outerr):
         self.excinfo = excinfo
         self.outerr = outerr
-        if excinfo is not None:
-            if excinfo.errisinstance((Skipped, Skipped2)):
-                outcome = "skipped"
-            else:
-                outcome = "failed"
-        else:
-            outcome = "passed"
-        self.outcome = outcome
 
 def basic_runner(item):
     """ returns a test report after having run the given test item. """
@@ -29,8 +22,10 @@
     capture = config._getcapture(path=item.fspath) 
     excinfo = None
     try:
+        outcome = "setupfailed"
         try:
             config._setupstate.prepare(item) 
+            outcome = "passed"
             item.execute()
         finally:
             out, err = capture.reset()
@@ -39,17 +34,28 @@
         raise
     except: 
         excinfo = py.code.ExceptionInfo()
-        if config.option.usepdb and not excinfo.errisinstance(Skipped):
-            py.__.test2.custompdb.post_mortem(excinfo._excinfo[2])
 
     # make report 
     trail = item._get_collector_trail()
+    repr_run = None
+    if excinfo is not None and outcome == "passed":
+        if excinfo.errisinstance((Skipped, Skipped2)):
+            outcome = "skipped"
+        else:
+            outcome = "failed"
     runnerinfo = RunnerInfo(excinfo, outerr)
-    repr_run = item.repr_run(runnerinfo)
     repr_path = item.repr_path()
-    return repevent.ItemTestReport(trail, runnerinfo.outcome, 
-                                   repr_run, repr_path)
-
+    if outcome != "setupfailed":
+        # dispatch to custom item function
+        repr_run = item.repr_run(runnerinfo)
+    else:
+        repr_run = present.python_repr_run(item, runnerinfo, 
+                title="setupfailure with: %s" % (repr_path[1],))
+    rep = repevent.ItemTestReport(trail, outcome, repr_run, repr_path)
+    if config.option.usepdb and rep.failed:
+        # xxx print rep.repr_run() ? 
+        py.__.test2.custompdb.post_mortem(excinfo._excinfo[2])
+    return rep 
 
 def fork_runner(item):
     def runforked():

Modified: py/branch/event/py/test2/testing/test_runner.py
==============================================================================
--- py/branch/event/py/test2/testing/test_runner.py	(original)
+++ py/branch/event/py/test2/testing/test_runner.py	Sun Jul 20 17:49:13 2008
@@ -104,7 +104,6 @@
         assert testrep.repr_run.find("sure\n") != -1
 
     def test_setupfailure(self):
-        py.test.skip("implement setupfailures")
         testrep = self.runtestfunc("""
             def setup_module(mod):
                 raise ValueError(10)
@@ -112,15 +111,39 @@
                 pass
         """)
         assert not testrep.passed
-        assert testrep.setupfailure 
-        assert testrep.failed # ???
-       
-        # xxx repr_run of setupfailures should always 
+        assert testrep.setupfailed
+        assert testrep.failed 
+
+        s = testrep.repr_run 
+        print s
+        exp = "setupfailure with: %s" %(testrep.repr_path[1])
+        assert s.find(exp) != -1
+        i = s.find("def ")
+        assert s[i+4:].startswith("setup_module")
+
+    def test_setupfailure_always_python_traceback(self):
+        item = self.makeitem("""
+            def setup_module(mod):
+                raise ValueError(10)
+            def testfunc():
+                pass
+        """)
+        runner = self.getrunner()
+        item.repr_run = lambda *args: "cusWRONG TRACEBACK!"
+        testrep = runner(item)
+        assert not testrep.passed
+        assert testrep.setupfailed
+        assert testrep.failed 
+        # repr_run of setupfailures should always 
         # display python Tracebacks starting from the 
         # failing setup function
+        s = testrep.repr_run 
+        print s
+        i = s.find("def ")
+        assert s[i+4:].startswith("setup_module")
 
     def test_setupfailure_on_eager_teardown(self):
-        py.test.skip("implement setupfailures")
+        py.test.skip("implement eager teardown")
         testrep = self.runtestfunc("""
             def testfunc():
                 pass



More information about the pytest-commit mailing list