Exemple #1
0
    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
Exemple #2
0
    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
Exemple #3
0
    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
Exemple #4
0
    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
Exemple #5
0
    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
Exemple #6
0
    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)
Exemple #7
0
    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)
Exemple #8
0
    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()
Exemple #9
0
    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()
Exemple #10
0
    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)
Exemple #11
0
    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')
Exemple #12
0
    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
Exemple #13
0
    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)
Exemple #14
0
    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)
Exemple #15
0
    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)
Exemple #16
0
    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)
Exemple #17
0
    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)
Exemple #18
0
    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)
Exemple #19
0
    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')