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 before_scenario(context: Context, scenario: Scenario): """ In this function, we launch a container, install ubuntu-advantage-tools and then capture an image. This image is then reused by each scenario, reducing test execution time. """ reason = _should_skip_tags(context, scenario.effective_tags) if reason: scenario.skip(reason=reason) return filter_series = context.config.filter_series given_a_series_match = re.match( "a `(.*)` machine with ubuntu-advantage-tools installed", scenario.steps[0].name, ) if filter_series and given_a_series_match: series = given_a_series_match.group(1) if series and series not in filter_series: scenario.skip( reason=("Skipping scenario outline series `{series}`." " Cmdline provided @series tags: {cmdline_series}". format(series=series, cmdline_series=filter_series))) return if "uses.config.check_version" in scenario.effective_tags: # before_step doesn't execute early enough to modify the step # so we perform the version step surgery here for step in scenario.steps: if step.text: step.text = step.text.replace( "{UACLIENT_BEHAVE_CHECK_VERSION}", context.config.check_version, )
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 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 before_scenario(context: Context, scenario: Scenario): """ In this function, we launch a container, install ubuntu-advantage-tools and then capture an image. This image is then reused by each scenario, reducing test execution time. """ reason = _should_skip_tags(context, scenario.effective_tags) if reason: scenario.skip(reason=reason)
def before_scenario(context: Context, scenario: Scenario): for tag in scenario.effective_tags: parts = tag.split(".") if parts[0] == "uses": val = context for attr in parts[1:]: val = getattr(val, attr, None) if val is None: scenario.skip( reason="Skipped because tag value was None: {}".format( tag))
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.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 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_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 == Status.skipped for s in steps] eq_(scenario.status, Status.skipped)
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_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 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 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_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, Status.skipped)
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 = Status.passed undefined_step.run.return_value = False undefined_step.status = Status.undefined assert scenario.run(self.runner) eq_(undefined_step.status, Status.undefined) eq_(scenario.status, Status.failed) # pylint: disable=protected-access self.context._set_root_attribute.assert_called_with("failed", True)
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_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)
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.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 _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)