def test_should_run_with_name_select(self): scenario_name = u"first scenario" scenario = Scenario("foo.feature", 17, u"Scenario", scenario_name) self.config.name = ['first .*', 'second .*'] self.config.name_re = Configuration.build_name_re(self.config.name) assert scenario.should_run_with_name_select(self.config)
def test_scenario_hooks_not_run_if_scenario_not_being_run(self): self.config.tag_expression.check.return_value = False # pylint: disable=no-member scenario = Scenario("foo.feature", 17, u"Scenario", u"foo") scenario.run(self.runner) assert not self.run_hook.called
def test_scenario_hooks_not_run_if_scenario_not_being_run(self): self.config.tags.check.return_value = False # pylint: disable=no-member scenario = Scenario('foo.feature', 17, u'Scenario', u'foo') scenario.run(self.runner) assert not self.run_hook.called
def build_scenario(self, name=u"", tags=None): if not self.current_feature: self.build_feature(u"feature_temp") filename = self.current_feature.filename line = self.current_feature.line + 1 scenario = Scenario(filename, line, u"Scenario", name, tags=tags) self.current_feature.add_scenario(scenario) self.current_scenario = scenario return scenario
def _scenario(self, keyword=u'k\xe9yword', name=u'name', tags=[], steps=[]): line = self.line tags = [Tag(name, line) for name in tags] return Scenario('<string>', line, keyword, name, tags=tags, steps=steps)
def test_handles_stdout_and_log_capture(self): self.config.stdout_capture = True self.config.log_capture = True self.config.tags.check.return_value = True # pylint: disable=no-member steps = [Mock(), Mock()] scenario = Scenario('foo.feature', 17, u'Scenario', u'foo', steps=steps) scenario.run(self.runner) self.runner.setup_capture.assert_called_with() self.runner.teardown_capture.assert_called_with()
def test_run_invokes_formatter_scenario_and_steps_correctly(self): self.config.stdout_capture = False self.config.log_capture = False self.config.tags.check.return_value = True # pylint: disable=no-member steps = [Mock(), Mock()] scenario = Scenario('foo.feature', 17, u'Scenario', u'foo', steps=steps) scenario.run(self.runner) self.formatters[0].scenario.assert_called_with(scenario) for step in steps: step.run.assert_called_with(self.runner)
def test_skipped_steps_set_step_status_and_scenario_status_if_not_set( self): self.config.stdout_capture = False self.config.log_capture = False self.config.tags.check.return_value = False # pylint: disable=no-member steps = [Mock(), Mock()] scenario = Scenario('foo.feature', 17, u'Scenario', u'foo', steps=steps) scenario.run(self.runner) assert False not in [s.status == 'skipped' for s in steps] eq_(scenario.status, 'skipped')
def test_skipped_steps_set_step_status_and_scenario_status_if_not_set( self): self.config.stdout_capture = False self.config.log_capture = False self.config.tag_expression.check.return_value = False # pylint: disable=no-member steps = [Mock(), Mock()] scenario = Scenario("foo.feature", 17, u"Scenario", u"foo", steps=steps) scenario.run(self.runner) assert False not in [s.status == Status.skipped for s in steps] assert scenario.status == Status.skipped
def _scenario(self, keyword=u'k\xe9yword', name=u'name', tags=None, steps=None): if tags is None: tags = [] if steps is None: steps = [] line = self.line tags = [Tag(name, line) for name in tags] return Scenario('<string>', line, keyword, name, tags=tags, steps=steps)
def _scenario(self, keyword=u"k\xe9yword", name=u"name", tags=None, steps=None): if tags is None: tags = [] if steps is None: steps = [] line = self.line tags = [Tag(name, line) for name in tags] return Scenario("<string>", line, keyword, name, tags=tags, steps=steps)
def test_failed_step_causes_context_failure_to_be_set(self): self.config.stdout_capture = False self.config.log_capture = False self.config.tags.check.return_value = True # pylint: disable=no-member steps = [ Mock(step_type="given", name="step0"), Mock(step_type="then", name="step1"), ] scenario = Scenario('foo.feature', 17, u'Scenario', u'foo', steps=steps) steps[0].run.return_value = False assert scenario.run(self.runner) # pylint: disable=protected-access self.context._set_root_attribute.assert_called_with('failed', True)
def test_undefined_step_causes_failed_scenario_status(self): self.config.stdout_capture = False self.config.log_capture = False self.config.tags.check.return_value = True # pylint: disable=no-member passed_step = Mock() undefined_step = Mock() steps = [passed_step, undefined_step] scenario = Scenario('foo.feature', 17, u'Scenario', u'foo', steps=steps) passed_step.run.return_value = True passed_step.status = 'passed' undefined_step.run.return_value = False undefined_step.status = 'undefined' assert scenario.run(self.runner) eq_(undefined_step.status, 'undefined') eq_(scenario.status, 'failed') # pylint: disable=protected-access self.context._set_root_attribute.assert_called_with('failed', True)
def test_failed_step_causes_remaining_steps_to_be_skipped(self): self.config.stdout_capture = False self.config.log_capture = False self.config.tags.check.return_value = True # pylint: disable=no-member steps = [Mock(), Mock()] scenario = Scenario('foo.feature', 17, u'Scenario', u'foo', steps=steps) steps[0].run.return_value = False steps[1].step_type = "when" steps[1].name = "step1" def step1_function(context): # pylint: disable=unused-argument pass my_step_registry = step_registry.StepRegistry() my_step_registry.add_step_definition("when", "step1", step1_function) with patch("behave.step_registry.registry", my_step_registry): assert scenario.run(self.runner) eq_(steps[1].status, 'skipped')
def test_undefined_step_causes_failed_scenario_status(self): self.config.stdout_capture = False self.config.log_capture = False self.config.tag_expression.check.return_value = True # pylint: disable=no-member passed_step = Mock() undefined_step = Mock() steps = [passed_step, undefined_step] scenario = Scenario("foo.feature", 17, u"Scenario", u"foo", steps=steps) passed_step.run.return_value = True passed_step.status = Status.passed undefined_step.run.return_value = False undefined_step.status = Status.undefined assert scenario.run(self.runner) assert undefined_step.status == Status.undefined assert scenario.status == Status.failed # pylint: disable=protected-access self.context._set_root_attribute.assert_called_with("failed", True)