[pypy-svn] r74735 - in pypy/trunk/py: _plugin _test

hpk at codespeak.net hpk at codespeak.net
Tue May 25 16:58:27 CEST 2010


Author: hpk
Date: Tue May 25 16:58:25 2010
New Revision: 74735

Modified:
   pypy/trunk/py/_plugin/pytest_default.py
   pypy/trunk/py/_plugin/pytest_helpconfig.py
   pypy/trunk/py/_plugin/pytest_pytester.py
   pypy/trunk/py/_plugin/pytest_terminal.py
   pypy/trunk/py/_test/session.py
Log:
introducing --maxfail=NUM option , hopefully the last 1.3.1 candidate


Modified: pypy/trunk/py/_plugin/pytest_default.py
==============================================================================
--- pypy/trunk/py/_plugin/pytest_default.py	(original)
+++ pypy/trunk/py/_plugin/pytest_default.py	Tue May 25 16:58:25 2010
@@ -62,9 +62,12 @@
 
 def pytest_addoption(parser):
     group = parser.getgroup("general", "running and selection options")
-    group._addoption('-x', '--exitfirst',
-               action="store_true", dest="exitfirst", default=False,
+    group._addoption('-x', '--exitfirst', action="store_true", default=False,
+               dest="exitfirst", 
                help="exit instantly on first error or failed test."),
+    group._addoption('--maxfail', metavar="num",
+               action="store", type="int", dest="maxfail", default=0,
+               help="exit after first num failures or errors.")
     group._addoption('-k',
         action="store", dest="keyword", default='',
         help="only run test items matching the given "
@@ -89,6 +92,9 @@
 
 def pytest_configure(config):
     setsession(config)
+    # compat
+    if config.getvalue("exitfirst"):
+        config.option.maxfail = 1
 
 def setsession(config):
     val = config.getvalue

Modified: pypy/trunk/py/_plugin/pytest_helpconfig.py
==============================================================================
--- pypy/trunk/py/_plugin/pytest_helpconfig.py	(original)
+++ pypy/trunk/py/_plugin/pytest_helpconfig.py	Tue May 25 16:58:25 2010
@@ -45,7 +45,7 @@
     options = [opt for opt in options if opt._long_opts]
     options.sort(key=lambda x: x._long_opts)
     for opt in options:
-        if not opt._long_opts:
+        if not opt._long_opts or not opt.dest:
             continue
         optstrings = list(opt._long_opts) # + list(opt._short_opts)
         optstrings = filter(None, optstrings)

Modified: pypy/trunk/py/_plugin/pytest_pytester.py
==============================================================================
--- pypy/trunk/py/_plugin/pytest_pytester.py	(original)
+++ pypy/trunk/py/_plugin/pytest_pytester.py	Tue May 25 16:58:25 2010
@@ -185,6 +185,7 @@
         return reports[0]
 
     def inline_run(self, *args):
+        args = ("-s", ) + args # otherwise FD leakage
         config = self.parseconfig(*args)
         config.pluginmanager.do_configure(config)
         session = config.initsession()

Modified: pypy/trunk/py/_plugin/pytest_terminal.py
==============================================================================
--- pypy/trunk/py/_plugin/pytest_terminal.py	(original)
+++ pypy/trunk/py/_plugin/pytest_terminal.py	Tue May 25 16:58:25 2010
@@ -312,12 +312,14 @@
         self._keyboardinterrupt_memo = excinfo.getrepr(funcargs=True)
 
     def _report_keyboardinterrupt(self):
-        self.write_sep("!", "KEYBOARD INTERRUPT")
         excrepr = self._keyboardinterrupt_memo
-        if self.config.option.verbose:
-            excrepr.toterminal(self._tw)
-        else:
-            excrepr.reprcrash.toterminal(self._tw)
+        msg = excrepr.reprcrash.message
+        self.write_sep("!", msg)
+        if "KeyboardInterrupt" in msg:
+            if self.config.getvalue("fulltrace"):
+                excrepr.toterminal(self._tw)
+            else:
+                excrepr.reprcrash.toterminal(self._tw)
 
     def _getcrashline(self, report):
         try:

Modified: pypy/trunk/py/_test/session.py
==============================================================================
--- pypy/trunk/py/_test/session.py	(original)
+++ pypy/trunk/py/_test/session.py	Tue May 25 16:58:25 2010
@@ -20,11 +20,14 @@
 
 class Session(object): 
     nodeid = ""
+    class Interrupted(KeyboardInterrupt):
+        """ signals an interrupted test run. """
+        
     def __init__(self, config):
         self.config = config
         self.pluginmanager = config.pluginmanager # shortcut 
         self.pluginmanager.register(self)
-        self._testsfailed = False
+        self._testsfailed = 0
         self._nomatch = False
         self.shouldstop = False
 
@@ -52,7 +55,7 @@
                         yield x 
                 self.config.hook.pytest_collectreport(report=rep)
             if self.shouldstop:
-                break
+                raise self.Interrupted(self.shouldstop)
 
     def filteritems(self, colitems):
         """ return items to process (some may be deselected)"""
@@ -86,9 +89,11 @@
         
     def pytest_runtest_logreport(self, report):
         if report.failed:
-            self._testsfailed = True
-            if self.config.option.exitfirst:
-                self.shouldstop = True
+            self._testsfailed += 1
+            maxfail = self.config.getvalue("maxfail")
+            if maxfail and self._testsfailed >= maxfail:
+                self.shouldstop = "stopping after %d failures" % (
+                    self._testsfailed)
     pytest_collectreport = pytest_runtest_logreport
 
     def sessionfinishes(self, exitstatus):
@@ -122,7 +127,8 @@
 
     def _mainloop(self, colitems):
         for item in self.collect(colitems): 
-            if self.shouldstop: 
-                break 
             if not self.config.option.collectonly: 
                 item.config.hook.pytest_runtest_protocol(item=item)
+            if self.shouldstop:
+                raise self.Interrupted(self.shouldstop)
+



More information about the Pypy-commit mailing list