Skip to content

Commit

Permalink
Merge pull request #41 from Jeff-Meadows/teardown
Browse files Browse the repository at this point in the history
Run flaky test reruns after tearDown.
  • Loading branch information
Jeff-Meadows committed May 5, 2015
2 parents c3e32c4 + 558fa71 commit a438f86
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 6 deletions.
50 changes: 46 additions & 4 deletions flaky/flaky_nose_plugin.py
Expand Up @@ -26,6 +26,7 @@ def __init__(self):
self._force_flaky = False
self._max_runs = None
self._min_passes = None
self._test_status = {}

def options(self, parser, env=os.environ):
"""
Expand All @@ -50,6 +51,51 @@ def configure(self, options, conf):
self._max_runs = options.max_runs
self._min_passes = options.min_passes

def startTest(self, test):
"""
Base class override. Called before a test is run.
Add the test to the test status tracker, so it can potentially
be rerun during stopTest.
:param test:
The test that is going to be run.
:type test:
:class:`nose.case.Test`
"""
# pylint:disable=invalid-name
self._test_status[test] = None

def stopTest(self, test):
"""
Base class override. Called after a test is run.
If the test was marked for rerun, rerun the test.
:param test:
The test that has been run.
:type test:
:class:`nose.case.Test`
"""
# pylint:disable=invalid-name
if self._test_status[test]:
test.run(self._flaky_result)
del self._test_status[test]

def _rerun_test(self, test):
"""
Base class override. Rerun a flaky test.
In this case, don't actually rerun the test, but mark it for
rerun during stopTest.
:param test:
The test that is going to be rerun.
:type test:
:class:`nose.case.Test`
"""
self._test_status[test] = True

def handleError(self, test, err):
"""
Baseclass override. Called when a test raises an exception.
Expand Down Expand Up @@ -169,10 +215,6 @@ def prepareTestCase(self, test):
self._make_test_flaky(
test, self._max_runs, self._min_passes)

def _rerun_test(self, test):
"""Base class override. Rerun a flaky test."""
test.run(self._flaky_result)

@staticmethod
def _get_test_callable_name(test):
"""
Expand Down
4 changes: 2 additions & 2 deletions test/test_flaky_nose_plugin.py
Expand Up @@ -281,7 +281,7 @@ def _test_flaky_plugin_handles_failure_or_error(
expected_test_case_calls = [call.address(), call.address()]
expected_result_calls = []
if expected_plugin_handles_failure:
expected_test_case_calls.append(call.run(self._mock_test_result))
expected_test_case_calls.append(('__hash__',))
expected_stream_calls = [call.writelines([
self._mock_test_method_name,
' failed ({0} runs remaining out of {1}).'.format(
Expand Down Expand Up @@ -381,7 +381,7 @@ def _test_flaky_plugin_handles_success(
),
])]
if expected_plugin_handles_success:
expected_test_case_calls.append(call.run(self._mock_test_result))
expected_test_case_calls.append(('__hash__',))
expected_stream_calls.append(
call.write(
'Running test again until it passes {0} times.\n'.format(
Expand Down

0 comments on commit a438f86

Please sign in to comment.