Commit 155123ee by Kevin Stone

Fixed running the background steps only after the Scenario before callbacks have executed.

Signed-off-by: Kevin Stone <kevinastone@gmail.com>
parent c51333d2
...@@ -696,6 +696,9 @@ class Scenario(object): ...@@ -696,6 +696,9 @@ class Scenario(object):
def run_scenario(almost_self, order=-1, outline=None, run_callbacks=False): def run_scenario(almost_self, order=-1, outline=None, run_callbacks=False):
try: try:
if self.background:
self.background.run(ignore_case)
all_steps, steps_passed, steps_failed, steps_undefined, reasons_to_fail = Step.run_all(self.steps, outline, run_callbacks, ignore_case, failfast=failfast) all_steps, steps_passed, steps_failed, steps_undefined, reasons_to_fail = Step.run_all(self.steps, outline, run_callbacks, ignore_case, failfast=failfast)
except: except:
if failfast: if failfast:
...@@ -1185,6 +1188,7 @@ class Feature(object): ...@@ -1185,6 +1188,7 @@ class Feature(object):
params.update(kw) params.update(kw)
current_scenario = Scenario.from_string(current, **params) current_scenario = Scenario.from_string(current, **params)
current_scenario.background = background
scenarios.append(current_scenario) scenarios.append(current_scenario)
return background, scenarios, description return background, scenarios, description
...@@ -1210,9 +1214,6 @@ class Feature(object): ...@@ -1210,9 +1214,6 @@ class Feature(object):
if not scenario.matches_tags(tags): if not scenario.matches_tags(tags):
continue continue
if self.background:
self.background.run(ignore_case)
scenarios_ran.extend(scenario.run(ignore_case, failfast=failfast)) scenarios_ran.extend(scenario.run(ignore_case, failfast=failfast))
except: except:
if failfast: if failfast:
......
...@@ -24,6 +24,7 @@ from lettuce import terminal ...@@ -24,6 +24,7 @@ from lettuce import terminal
from lettuce.terrain import after from lettuce.terrain import after
from lettuce.terrain import before from lettuce.terrain import before
from lettuce.terrain import world
def wrt(what): def wrt(what):
...@@ -131,6 +132,16 @@ def print_step_ran(step): ...@@ -131,6 +132,16 @@ def print_step_ran(step):
@before.each_scenario @before.each_scenario
def print_scenario_running(scenario): def print_scenario_running(scenario):
if scenario.background:
# Only print the background on the first scenario run
# So, we determine if this was called previously with the attached background.
# If so, skip the print_scenario() since we'll call it again in the after_background.
if not hasattr(world, 'background_scenario_holder'):
world.background_scenario_holder = {}
if scenario.background not in world.background_scenario_holder:
# We haven't seen this background before, add our 1st scenario
world.background_scenario_holder[scenario.background] = scenario
return
string = scenario.represented() string = scenario.represented()
string = wrap_file_and_line(string, '\033[1;30m', '\033[0m') string = wrap_file_and_line(string, '\033[1;30m', '\033[0m')
write_out("\n\033[1;37m%s" % string) write_out("\n\033[1;37m%s" % string)
...@@ -258,3 +269,9 @@ def print_background_running(background): ...@@ -258,3 +269,9 @@ def print_background_running(background):
wrt('\033[1;37m') wrt('\033[1;37m')
wrt(background.represented()) wrt(background.represented())
wrt('\033[0m\n') wrt('\033[0m\n')
@after.each_background
def print_first_scenario_running(background, results):
scenario = world.background_scenario_holder[background]
print_scenario_running(scenario)
...@@ -21,6 +21,7 @@ from lettuce import core ...@@ -21,6 +21,7 @@ from lettuce import core
from lettuce import strings from lettuce import strings
from lettuce.terrain import after from lettuce.terrain import after
from lettuce.terrain import before from lettuce.terrain import before
from lettuce.terrain import world
def wrt(what): def wrt(what):
...@@ -48,6 +49,16 @@ def print_step_running(step): ...@@ -48,6 +49,16 @@ def print_step_running(step):
@before.each_scenario @before.each_scenario
def print_scenario_running(scenario): def print_scenario_running(scenario):
if scenario.background:
# Only print the background on the first scenario run
# So, we determine if this was called previously with the attached background.
# If so, skip the print_scenario() since we'll call it again in the after_background.
if not hasattr(world, 'background_scenario_holder'):
world.background_scenario_holder = {}
if scenario.background not in world.background_scenario_holder:
# We haven't seen this background before, add our 1st scenario
world.background_scenario_holder[scenario.background] = scenario
return
wrt('\n') wrt('\n')
wrt(scenario.represented()) wrt(scenario.represented())
...@@ -59,6 +70,12 @@ def print_background_running(background): ...@@ -59,6 +70,12 @@ def print_background_running(background):
wrt('\n') wrt('\n')
@after.each_background
def print_first_scenario_running(background, results):
scenario = world.background_scenario_holder[background]
print_scenario_running(scenario)
@after.outline @after.outline
def print_outline(scenario, order, outline, reasons_to_fail): def print_outline(scenario, order, outline, reasons_to_fail):
table = strings.dicts_to_string(scenario.outlines, scenario.keys) table = strings.dicts_to_string(scenario.outlines, scenario.keys)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment