[py-svn] r57229 - in py/branch/event/py/test2: . dsession report terminal testing

hpk at codespeak.net hpk at codespeak.net
Wed Aug 13 18:54:14 CEST 2008


Author: hpk
Date: Wed Aug 13 18:54:12 2008
New Revision: 57229

Removed:
   py/branch/event/py/test2/terminal/
Modified:
   py/branch/event/py/test2/config.py
   py/branch/event/py/test2/dsession/dsession.py
   py/branch/event/py/test2/report/base.py
   py/branch/event/py/test2/report/terminal.py
   py/branch/event/py/test2/session.py
   py/branch/event/py/test2/testing/test_config.py
Log:
remove old way to do looponfailing, introduce new way to dsession.


Modified: py/branch/event/py/test2/config.py
==============================================================================
--- py/branch/event/py/test2/config.py	(original)
+++ py/branch/event/py/test2/config.py	Wed Aug 13 18:54:12 2008
@@ -156,6 +156,7 @@
         cls = self._getsessionclass()
         session = cls(self)
         session.fixoptions()
+        session.reporter = self.initreporter(session.bus)
         return session
 
     def _getsessionclass(self): 

Modified: py/branch/event/py/test2/dsession/dsession.py
==============================================================================
--- py/branch/event/py/test2/dsession/dsession.py	(original)
+++ py/branch/event/py/test2/dsession/dsession.py	Wed Aug 13 18:54:12 2008
@@ -14,6 +14,8 @@
 from py.__.test2.session import Session
 from py.__.test2.runner import OutcomeRepr
 from py.__.test2 import outcome 
+from py.__.test2.dsession import looponfailing 
+
 
 import Queue 
 
@@ -55,8 +57,6 @@
         # conflicting options
         if option.looponfailing and option.usepdb:
             raise ValueError, "--looponfailing together with --pdb not supported."
-        if option.looponfailing and option.dist:
-            raise ValueError, "--looponfailing together with --dist not supported."
         if option.executable and option.usepdb:
             raise ValueError, "--exec together with --pdb not supported."
         if option.keyword_oneshot and not option.keyword:
@@ -79,9 +79,38 @@
 
     def main(self):
         colitems = [self.config.getfsnode(arg) for arg in self.config.args]
-        self.sessionstarts()
+        if self.config.option.looponfailing:
+            self.runsession_looponfailing(colitems)
+            exitstatus = 0
+        else:
+            exitstatus = self.runsession(colitems)
+        return exitstatus
+
+    def runsession_looponfailing(self, initialcolitems):
+        eventrecorder = looponfailing.EventRecorder(self.bus)
+        statrecorder = looponfailing.StatRecorder([self.config.topdir])
+        colitems = initialcolitems
+        while 1:
+            self.reporter.startnewrun()
+            self.runsession(colitems[:])
+            reports = eventrecorder.getfailures()
+            eventrecorder.clear()
+            self.bus.notify(event.LooponfailingInfo(reports, [self.config.topdir]))
+            if reports:
+                colitems = [rep.colitem for rep in reports]
+            else:
+                if colitems != initialcolitems:
+                    colitems = initialcolitems
+                    continue # runagain
+            statrecorder.waitonchange(checkinterval=2.0)
+            
+
+    def runsession(self, colitems):
+        self.bus.notify(event.SessionStart(self))
+        self.setup_hosts()
         exitstatus = self.loop(colitems)
-        self.sessionfinishes(exitstatus=exitstatus)
+        self.bus.notify(event.SessionFinish(self, exitstatus=exitstatus))
+        self.teardown_hosts()
         return exitstatus
 
     def loop_once(self, loopstate):
@@ -229,20 +258,14 @@
         rep = event.ItemTestReport(item, failed=outcome)
         self.bus.notify(rep)
 
-    def sessionstarts(self):
+    def setup_hosts(self):
         """ setup any neccessary resources ahead of the test run. """
-        self.reporter = self.config.initreporter(self.bus)
-        self.bus.notify(event.SessionStart(self))
         self.hm = HostManager(self)
         self.hm.setup_hosts(notify=self.queue.put)
         for host in self.hm.hosts:
             self.addhost(host)
 
-    def sessionfinishes(self, exitstatus):
+    def teardown_hosts(self):
         """ teardown any resources after a test run. """ 
-        self.bus.notify(event.SessionFinish(self, exitstatus=exitstatus))
-        self.reporter.deactivate()
-        #for host in self.hosts:
-        #    host.shutdown()    
         for host in self.hosts:
             host.gw.exit()

Modified: py/branch/event/py/test2/report/base.py
==============================================================================
--- py/branch/event/py/test2/report/base.py	(original)
+++ py/branch/event/py/test2/report/base.py	Wed Aug 13 18:54:12 2008
@@ -3,13 +3,16 @@
 
 class BaseReporter(object):
     def __init__(self, bus=None):
-        self._passed = []
-        self._skipped = []
-        self._failed = []
+        self.startnewrun()
         self._bus = bus
         if bus:
             self._bus.subscribe(self.processevent)
 
+    def startnewrun(self):
+        self._passed = []
+        self._skipped = []
+        self._failed = []
+
     def deactivate(self):
         if self._bus:
             self._bus.unsubscribe(self.processevent)

Modified: py/branch/event/py/test2/report/terminal.py
==============================================================================
--- py/branch/event/py/test2/report/terminal.py	(original)
+++ py/branch/event/py/test2/report/terminal.py	Wed Aug 13 18:54:12 2008
@@ -10,11 +10,15 @@
     def __init__(self, config, file=None, bus=None):
         super(TerminalReporter, self).__init__(bus=bus)
         self.config = config
-        self.currentfspath = None 
         self.curdir = py.path.local()
         if file is None:
             file = py.std.sys.stdout
         self._tw = py.io.TerminalWriter(file)
+        self.startnewrun()
+
+    def startnewrun(self):
+        self.currentfspath = None 
+        super(TerminalReporter, self).startnewrun()
 
     def write_fspath_result(self, fspath, res):
         if fspath != self.currentfspath:
@@ -76,12 +80,11 @@
     def rep_LooponfailingInfo(self, ev):
         self._tw.sep("#", "LOOPONFAILING")
         if ev.failreports:
-            self.write_line("")
             for report in ev.failreports:
-                if isinstance(report.colitem, py.test2.collect.Function):
+                try:
                     loc = report.outcome.longrepr.reprcrash
-                else:
-                    loc = str(report.colitem)
+                except AttributeError:
+                    loc = str(report.outcome.longrepr)[:50]
                 self.write_line(loc)
         self.write_line("")
         self.write_line("watching files below:")

Modified: py/branch/event/py/test2/session.py
==============================================================================
--- py/branch/event/py/test2/session.py	(original)
+++ py/branch/event/py/test2/session.py	Wed Aug 13 18:54:12 2008
@@ -81,7 +81,6 @@
 
     def sessionstarts(self):
         """ setup any neccessary resources ahead of the test run. """
-        self.reporter = self.config.initreporter(self.bus)
         self.bus.notify(event.SessionStart(self))
         self._failurelist = []
         self.bus.subscribe(self._processfailures)

Modified: py/branch/event/py/test2/testing/test_config.py
==============================================================================
--- py/branch/event/py/test2/testing/test_config.py	(original)
+++ py/branch/event/py/test2/testing/test_config.py	Wed Aug 13 18:54:12 2008
@@ -227,8 +227,7 @@
         self.tmpdir.join("conftest.py").write(py.code.Source("""
             from py.__.test2.session import Session
             class MySession(Session):
-                def __init__(self, config, reporter=None):
-                    self.config = config 
+                pass
         """)) 
         config = py.test2.config._reparse(["--session=MySession", self.tmpdir])
         session = config.initsession()



More information about the pytest-commit mailing list