def patch_scenario_with_autoretry(scenario, max_attempts=3):
 def scenario_run_with_retries(scenario_run, *args, **kwargs):
  for attempt in range(1, (max_attempts + 1)):
   if (not scenario_run(*args, **kwargs)):
    if (attempt > 1):
     message = u'AUTO-RETRY SCENARIO PASSED (after {0} attempts)'
     print(message.format(attempt))
    return False
   if (attempt < max_attempts):
    print(u'AUTO-RETRY SCENARIO (attempt {0})'.format(attempt))
  message = u'AUTO-RETRY SCENARIO FAILED (after {0} attempts)'
  print(message.format(max_attempts))
  return True
 if isinstance(scenario, ScenarioOutline):
  scenario_outline = scenario
  for scenario in scenario_outline.scenarios:
   scenario_run = scenario.run
   scenario.run = functools.partial(scenario_run_with_retries, scenario_run)
 else:
  scenario_run = scenario.run
  scenario.run = functools.partial(scenario_run_with_retries, scenario_run)

def patch_scenario_with_autoretry ( scenario , max_attempts = 3 ) : def scenario_run_with_retries ( scenario_run , * args , ** kwargs ) : for attempt in range ( 1 , ( max_attempts + 1 ) ) : if ( not scenario_run ( * args , ** kwargs ) ) : if ( attempt > 1 ) : message = u'AUTO-RETRY SCENARIO PASSED (after {0} attempts)' print ( message . format ( attempt ) ) return False if ( attempt < max_attempts ) : print ( u'AUTO-RETRY SCENARIO (attempt {0})' . format ( attempt ) ) message = u'AUTO-RETRY SCENARIO FAILED (after {0} attempts)' print ( message . format ( max_attempts ) ) return True if isinstance ( scenario , ScenarioOutline ) : scenario_outline = scenario for scenario in scenario_outline . scenarios : scenario_run = scenario . run scenario . run = functools . partial ( scenario_run_with_retries , scenario_run ) else : scenario_run = scenario . run scenario . run = functools . partial ( scenario_run_with_retries , scenario_run )
monkey-patches :func:~behave .