1"""
2Stop the test run after the first error or failure.
3
4This plugin implements :func:`testOutcome` and sets
5``event.result.shouldStop`` if it sees an outcome with exc_info that
6is not expected.
7
8"""
9
10from nose2 import events
11
12
13__unittest = True
14
15
16class FailFast(events.Plugin):
17
18    """Stop the test run after error or failure"""
19    commandLineSwitch = (
20        'F', 'fail-fast', 'Stop the test run after the first error or failure')
21
22    def resultCreated(self, event):
23        """Mark new result"""
24        if hasattr(event.result, 'failfast'):
25            event.result.failfast = True
26
27    def testOutcome(self, event):
28        """Stop on unexpected error or failure"""
29        if event.exc_info and not event.expected:
30            event.result.shouldStop = True
31