Skip to content

Commit b57bea0

Browse files
committed
Add stop on first fail option
Similar to nosetests -x/--stop arg.
1 parent 74bdd7d commit b57bea0

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

bin/jp-compliance

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,11 @@ class ComplianceTestRunner(object):
7878
self.tests = tests
7979
self.jp_executable = exe
8080

81-
def run_tests(self):
81+
def run_tests(self, stop_first_fail):
8282
for test_case in self._test_cases():
8383
if self._should_run(test_case):
84-
self._run_test(test_case)
84+
if not self._run_test(test_case) and stop_first_fail:
85+
return
8586

8687
def _should_run(self, test_case):
8788
if not self.tests:
@@ -143,17 +144,21 @@ class ComplianceTestRunner(object):
143144
expected = test_case['result']
144145
if not actual == expected:
145146
self._show_failure(actual, test_case)
147+
return False
146148
else:
147149
sys.stdout.write('.')
148150
sys.stdout.flush()
151+
return True
149152
else:
150153
error_type = test_case['error']
151154
# For errors, we expect the error type on stderr.
152155
if error_type not in stderr:
153156
self._show_failure_for_error(stderr, test_case)
157+
return False
154158
else:
155159
sys.stdout.write('.')
156160
sys.stdout.flush()
161+
return True
157162

158163
def _show_failure(self, actual, test_case):
159164
test_case['actual'] = json.dumps(actual)
@@ -218,13 +223,15 @@ def main():
218223
'These values can then be used with the '
219224
'"-t/--tests" argument. If this argument is '
220225
'specified, no tests will actually be run.'))
226+
parser.add_argument('-s', '--stop-first-fail', action='store_true',
227+
help='Stop running tests after a single test fails.')
221228
args = parser.parse_args()
222229
runner = ComplianceTestRunner(args.exe, args.tests)
223230
if args.list:
224231
display_available_tests(runner.get_compliance_test_files())
225232
else:
226233
try:
227-
runner.run_tests()
234+
runner.run_tests(args.stop_first_fail)
228235
except Exception, e:
229236
sys.stderr.write(str(e))
230237
sys.stderr.write("\n")

0 commit comments

Comments
 (0)