aboutsummaryrefslogtreecommitdiff
path: root/py
diff options
context:
space:
mode:
authorHolger Krekel <holger.krekel@gmail.com>2010-05-25 14:58:25 +0000
committerHolger Krekel <holger.krekel@gmail.com>2010-05-25 14:58:25 +0000
commit5b530d5cf719e87fdd9c9091d6fbc0c366dd6f18 (patch)
tree451de6ec2655432048af3ac7d2fa64c1c018b258 /py
parentApply last patch of issue361. (diff)
downloadpypy-5b530d5cf719e87fdd9c9091d6fbc0c366dd6f18.tar.gz
pypy-5b530d5cf719e87fdd9c9091d6fbc0c366dd6f18.tar.bz2
pypy-5b530d5cf719e87fdd9c9091d6fbc0c366dd6f18.zip
introducing --maxfail=NUM option , hopefully the last 1.3.1 candidate
Diffstat (limited to 'py')
-rw-r--r--py/_plugin/pytest_default.py10
-rw-r--r--py/_plugin/pytest_helpconfig.py2
-rw-r--r--py/_plugin/pytest_pytester.py1
-rw-r--r--py/_plugin/pytest_terminal.py12
-rw-r--r--py/_test/session.py20
5 files changed, 30 insertions, 15 deletions
diff --git a/py/_plugin/pytest_default.py b/py/_plugin/pytest_default.py
index 3d3af35212..287331736b 100644
--- a/py/_plugin/pytest_default.py
+++ b/py/_plugin/pytest_default.py
@@ -62,9 +62,12 @@ def pytest_report_iteminfo(item):
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_addoption(parser):
def pytest_configure(config):
setsession(config)
+ # compat
+ if config.getvalue("exitfirst"):
+ config.option.maxfail = 1
def setsession(config):
val = config.getvalue
diff --git a/py/_plugin/pytest_helpconfig.py b/py/_plugin/pytest_helpconfig.py
index 480b57d933..f5f5f7501d 100644
--- a/py/_plugin/pytest_helpconfig.py
+++ b/py/_plugin/pytest_helpconfig.py
@@ -45,7 +45,7 @@ def pytest_configure(__multicall__, config):
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)
diff --git a/py/_plugin/pytest_pytester.py b/py/_plugin/pytest_pytester.py
index 0fb4f24de3..bb6790d75c 100644
--- a/py/_plugin/pytest_pytester.py
+++ b/py/_plugin/pytest_pytester.py
@@ -185,6 +185,7 @@ class TmpTestdir:
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()
diff --git a/py/_plugin/pytest_terminal.py b/py/_plugin/pytest_terminal.py
index f844e76199..7ed0ca85e7 100644
--- a/py/_plugin/pytest_terminal.py
+++ b/py/_plugin/pytest_terminal.py
@@ -312,12 +312,14 @@ class TerminalReporter:
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:
diff --git a/py/_test/session.py b/py/_test/session.py
index 7f11e75083..47e93e5d2d 100644
--- a/py/_test/session.py
+++ b/py/_test/session.py
@@ -20,11 +20,14 @@ Collector = py.test.collect.Collector
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 @@ class Session(object):
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 @@ class Session(object):
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 @@ class Session(object):
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)
+