Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated fail-fast plugin to take 'n' as number of failures to stop the run #616

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 36 additions & 7 deletions nose2/plugins/failfast.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,47 @@
class FailFast(events.Plugin):
"""Stop the test run after error or failure"""

commandLineSwitch = (
"F",
"fail-fast",
"Stop the test run after the first error or failure",
)
configSection = "failfast"

def __init__(self):
"""Initialize failfast as stop and failcount as current count"""
self.failfast = 0
self.failcount = 0
self.addArgument(
self.setFailFast,
"F",
"fail-fast",
"Stop the test run after the first error or failure (1 = auto)",
)
# Number of failures to stop the execution
self.failfast = self.config.as_int("failures", 0)

def handleArgs(self, args):
"""Register if fail-fast is >0 in cfg or command-line"""
if self.failfast > 0:
self.register()

def setFailFast(self, num):
"""CB to parse and set failcount"""
try:
self.failfast = int(num[0])
except ValueError:
# Invalid fastfail argument, has to be integer and greater than 0
self.failfast = 0

def resultCreated(self, event):
"""Mark new result"""
if hasattr(event.result, "failfast"):
event.result.failfast = True
# event.result.failfast = True
# Set failfast as True when current failure count matches failcount
if self.failcount >= self.failfast:
event.result.failfast = True

def testOutcome(self, event):
"""Stop on unexpected error or failure"""
if event.exc_info and not event.expected:
event.result.shouldStop = True
# event.result.shouldStop = True
# Check if current count reached failcount
self.failcount += 1
if self.failcount >= self.failfast:
event.result.shouldStop = True
4 changes: 2 additions & 2 deletions nose2/tests/functional/test_subtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,11 +379,11 @@ def test_failure(self):
def test_failfast(self):
proc = self.runIn(
"scenario/subtests",
"--fail-fast",
"--fail-fast=1",
"-v",
"test_subtests.Case.test_subtest_failure",
)
self.assertTestRunOutputMatches(proc, stderr="Ran 1 test")
self.assertTestRunOutputMatches(proc, stderr=r"test_subtest_failure.*\(i=1\)")
self.assertTestRunOutputMatches(proc, stderr=r"FAILED \(failures=1\)")
self.assertTestRunOutputMatches(proc, stderr=r"FAILED \(failures=3\)")
self.assertEqual(proc.poll(), 1)