Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_something():
pass
flaky_attribute = dict((
(attr, getattr(
test_something,
attr,
None
)) for attr in FlakyNames()
))
self.assertIsNotNone(flaky_attribute)
self.assertDictContainsSubset(
{
FlakyNames.MIN_PASSES: min_passes,
FlakyNames.MAX_RUNS: max_runs,
FlakyNames.CURRENT_PASSES: 0,
FlakyNames.CURRENT_RUNS: 0,
FlakyNames.CURRENT_ERRORS: None
},
flaky_attribute
)
Then rerun the test.
:param err:
Information about the test failure (from sys.exc_info())
:type err:
`tuple` of `class`, :class:`Exception`, `traceback`
:param flaky:
Dictionary of flaky attributes
:type flaky:
`dict` of `unicode` to varies
:param name:
The test name
:type name:
`unicode`
"""
max_runs = flaky[FlakyNames.MAX_RUNS]
runs_left = max_runs - flaky[FlakyNames.CURRENT_RUNS]
message = self._retry_failure_message.format(
runs_left,
max_runs,
)
self._log_test_failure(name, err, message)
:return:
Default flaky attributes to set on a flaky test.
:rtype:
`dict`
"""
if max_runs is None:
max_runs = 2
if min_passes is None:
min_passes = 1
if min_passes <= 0:
raise ValueError('min_passes must be positive')
if max_runs < min_passes:
raise ValueError('min_passes cannot be greater than max_runs!')
return {
FlakyNames.MAX_RUNS: max_runs,
FlakyNames.MIN_PASSES: min_passes,
FlakyNames.CURRENT_RUNS: 0,
FlakyNames.CURRENT_PASSES: 0,
FlakyNames.RERUN_FILTER: FilterWrapper(rerun_filter or _true),
}