Skip to content

Commit c5550bc

Browse files
committed
Adding Failed exception to manage maxfail behavior
1 parent 3676da5 commit c5550bc

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

_pytest/main.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ def wrap_session(config, doit):
110110
session.exitstatus = doit(config, session) or 0
111111
except UsageError:
112112
raise
113+
except Failed:
114+
session.exitstatus = EXIT_TESTSFAILED
113115
except KeyboardInterrupt:
114116
excinfo = _pytest._code.ExceptionInfo()
115117
if initstate < 2 and isinstance(excinfo.value, exit.Exception):
@@ -169,6 +171,8 @@ def pytest_runtestloop(session):
169171
item.config.hook.pytest_runtest_protocol(item=item, nextitem=nextitem)
170172
if session.shouldstop:
171173
raise session.Interrupted(session.shouldstop)
174+
if session.shouldfail:
175+
raise session.Failed(session.shouldfail)
172176
return True
173177

174178

@@ -590,15 +594,21 @@ class Interrupted(KeyboardInterrupt):
590594
__module__ = 'builtins' # for py3
591595

592596

597+
class Failed(Exception):
598+
""" signals an stop as failed test run. """
599+
600+
593601
class Session(FSCollector):
594602
Interrupted = Interrupted
603+
Failed = Failed
595604

596605
def __init__(self, config):
597606
FSCollector.__init__(self, config.rootdir, parent=None,
598607
config=config, session=self)
599608
self.testsfailed = 0
600609
self.testscollected = 0
601610
self.shouldstop = False
611+
self.shouldfail = False
602612
self.trace = config.trace.root.get("collection")
603613
self._norecursepatterns = config.getini("norecursedirs")
604614
self.startdir = py.path.local()
@@ -618,7 +628,7 @@ def pytest_runtest_logreport(self, report):
618628
self.testsfailed += 1
619629
maxfail = self.config.getvalue("maxfail")
620630
if maxfail and self.testsfailed >= maxfail:
621-
self.shouldstop = "stopping after %d failures" % (
631+
self.shouldfail = "stopping after %d failures" % (
622632
self.testsfailed)
623633
pytest_collectreport = pytest_runtest_logreport
624634

0 commit comments

Comments
 (0)