def test_running_a_feature(self): """ Test running a feature """ data = threading.local() data.step_was_called = False def some_step(step): data.step_was_called = True feature = Feature(1, "Feature", "Some feature", "somefile.feature", 1) scenario = Scenario(1, 1, "Scenario", "Some scenario", "somefile.feature", 2, feature) feature.scenarios.append(scenario) step = Step(1, "Some step", "somefile.feature", 3, scenario, True) step.definition_func = some_step argument_match_mock = Mock() argument_match_mock.evaluate.return_value = (tuple(), {}) step.argument_match = argument_match_mock scenario.steps.append(step) hook_mock = Mock() hook_mock.call.return_value = True runner = Runner(hook_mock) runner.run_feature(feature) step.state.should.be.equal(Step.State.PASSED) data.step_was_called.should.be.true
def test_running_a_feature(self): """ Test running a feature """ data = threading.local() data.step_was_called = False def some_step(step): data.step_was_called = True feature = Feature(1, "Feature", "Some feature", "somefile.feature", 1) scenario = Scenario(1, 1, "Scenario", "Some scenario", "somefile.feature", 2, feature) feature.scenarios.append(scenario) step = Step(1, "Some step", "somefile.feature", 3, scenario, True) step.definition_func = some_step step.arguments = tuple() step.keyword_arguments = {} scenario.steps.append(step) hook_mock = Mock() hook_mock.call.return_value = True runner = Runner(hook_mock) runner.run_feature(feature) step.state.should.be.equal(Step.State.PASSED) data.step_was_called.should.be.true
def test_runner_should_call_hooks_when_running_a_feature( hook_registry, default_config, mocker): """The Runner should call the ``each_feature`` hooks when running a Feature""" # given runner = Runner(default_config, None, hook_registry) feature_mock = mocker.MagicMock(name="Feature") # when runner.run_feature(feature_mock) # then hook_registry.call.assert_has_calls([ call("each_feature", "before", False, feature_mock), call("each_feature", "after", False, feature_mock), ])
def test_runner_should_run_each_rule_in_a_feature(hook_registry, default_config, mocker): """The Runner should run each Rule from a Feature""" # given runner = Runner(default_config, None, hook_registry) feature_mock = mocker.MagicMock(name="Feature") first_rule = mocker.MagicMock(name="First Rule") second_rule = mocker.MagicMock(name="Second Rule") feature_mock.rules = [first_rule, second_rule] runner.run_rule = mocker.MagicMock() # when runner.run_feature(feature_mock) # then runner.run_rule.assert_has_calls([call(first_rule), call(second_rule)])
def test_runner_should_exit_for_failed_rule_if_early_exit_flag_is_set( hook_registry, default_config, mocker): """The Runner should exit for a failed Rule if the early exit flag is set""" # given default_config.early_exit = True runner = Runner(default_config, None, hook_registry) runner.run_rule = mocker.MagicMock() runner.run_rule.side_effect = [State.PASSED, State.FAILED, State.PASSED] feature_mock = mocker.MagicMock(name="Feature") first_rule = mocker.MagicMock(name="First Rule") second_rule = mocker.MagicMock(name="Second Rule") third_rule = mocker.MagicMock(name="Third Rule") feature_mock.rules = [first_rule, second_rule, third_rule] # when runner.run_feature(feature_mock) # then runner.run_rule.assert_has_calls([call(first_rule), call(second_rule)])
def test_runner_should_only_run_rule_which_need_to_be_run( hook_registry, default_config, mocker): """The Runner should run only the Rules which need to be run""" # given runner = Runner(default_config, None, hook_registry) runner.run_rule = mocker.MagicMock() feature_mock = mocker.MagicMock(name="Feature") first_rule = mocker.MagicMock(name="First Rule") first_rule.has_to_run.return_value = True second_rule = mocker.MagicMock(name="Second Rule") second_rule.has_to_run.return_value = False third_rule = mocker.MagicMock(name="Third Rule") third_rule.has_to_run.return_value = True feature_mock.rules = [first_rule, second_rule, third_rule] # when runner.run_feature(feature_mock) # then runner.run_rule.assert_has_calls([call(first_rule), call(third_rule)])
def test_start_run_should_iterate_all_given_features(hook_registry, default_config, mocker): """All Features given to run should be iterated""" # given runner = Runner(default_config, None, hook_registry) runner.run_feature = mocker.MagicMock() first_feature = mocker.MagicMock(name="First Feature") second_feature = mocker.MagicMock(name="Second Feature") # when runner.start([first_feature, second_feature]) # given runner.run_feature.assert_has_calls( [call(first_feature), call(second_feature)])
def test_should_return_good_status_if_all_features_passed( hook_registry, default_config, mocker): """ The Runner should return a good status when finished if all features passed in normal mode """ # given runner = Runner(default_config, None, hook_registry) runner.run_feature = mocker.MagicMock() runner.run_feature.side_effect = [State.PASSED, State.PASSED] first_feature = mocker.MagicMock(name="First Feature", state=State.PASSED) second_feature = mocker.MagicMock(name="Second Feature", state=State.PASSED) # when status = runner.start([first_feature, second_feature]) # given assert status
def test_returncode_of_runner(self): """ Test returncode of run functions in Runner """ def some_passed_step(step): pass def some_failed_step(step): raise AttributeError( "I expect this error to test the behavior of a failed step") feature = Feature(1, "Feature", "Some feature", "somefile.feature", 1) scenario = Scenario(1, 1, "Scenario", "Some scenario", "somefile.feature", 2, feature) feature.scenarios.append(scenario) step1 = Step(1, "Some passed step", "somefile.feature", 3, scenario, True) step1.definition_func = some_passed_step argument_match_mock = Mock() argument_match_mock.evaluate.return_value = (tuple(), {}) step1.argument_match = argument_match_mock scenario.steps.append(step1) step2 = Step(2, "Some failed step", "somefile.feature", 4, scenario, True) step2.definition_func = some_failed_step argument_match_mock = Mock() argument_match_mock.evaluate.return_value = (tuple(), {}) step2.argument_match = argument_match_mock scenario.steps.append(step2) hook_mock = Mock() hook_mock.call.return_value = True runner = Runner(hook_mock) returncode = runner.run_feature(feature) returncode.should.be.equal(1) step1.state.should.be.equal(Step.State.PASSED) step2.state.should.be.equal(Step.State.FAILED) scenario.state.should.be.equal(Step.State.FAILED) feature.state.should.be.equal(Step.State.FAILED)
def test_should_only_run_feature_which_have_to_run(hook_registry, default_config, mocker): """The Runner should only run features which need to be run""" # given runner = Runner(default_config, None, hook_registry) runner.run_feature = mocker.MagicMock() first_feature = mocker.MagicMock(name="First Feature") first_feature.has_to_run.return_value = True second_feature = mocker.MagicMock(name="Second Feature") second_feature.has_to_run.return_value = False third_feature = mocker.MagicMock(name="Third Feature") third_feature.has_to_run.return_value = True # when runner.start([first_feature, second_feature, third_feature]) # given runner.run_feature.assert_has_calls( [call(first_feature), call(third_feature)])
def test_should_exit_for_failed_feature_if_early_exit_set( hook_registry, default_config, mocker): """The Runner should exit early if a Feature failes if the early exit flag is set""" # given default_config.early_exit = True runner = Runner(default_config, None, hook_registry) runner.run_feature = mocker.MagicMock() runner.run_feature.side_effect = [State.PASSED, State.FAILED, State.PASSED] first_feature = mocker.MagicMock(name="First Feature") second_feature = mocker.MagicMock(name="Second Feature") third_feature = mocker.MagicMock(name="Third Feature") # when runner.start([first_feature, second_feature, third_feature]) # given runner.run_feature.assert_has_calls( [call(first_feature), call(second_feature)])
def test_should_return_good_status_if_all_features_failed_in_wip_mode( hook_registry, default_config, mocker): """ The Runner should return a good status when finished if all features failed in WIP mode """ # given default_config.wip_mode = True runner = Runner(default_config, None, hook_registry) runner.run_feature = mocker.MagicMock() runner.run_feature.side_effect = [State.FAILED, State.FAILED] first_feature = mocker.MagicMock(name="First Feature", state=State.FAILED) second_feature = mocker.MagicMock(name="Second Feature", state=State.FAILED) # when status = runner.start([first_feature, second_feature]) # given assert status
def test_returncode_of_runner(self): """ Test returncode of run functions in Runner """ def some_passed_step(step): pass def some_failed_step(step): raise AttributeError("I expect this error to test the behavior of a failed step") feature = Feature(1, "Feature", "Some feature", "somefile.feature", 1) scenario = Scenario(1, 1, "Scenario", "Some scenario", "somefile.feature", 2, feature) feature.scenarios.append(scenario) step1 = Step(1, "Some passed step", "somefile.feature", 3, scenario, True) step1.definition_func = some_passed_step step1.arguments = tuple() step1.keyword_arguments = {} scenario.steps.append(step1) step2 = Step(2, "Some failed step", "somefile.feature", 4, scenario, True) step2.definition_func = some_failed_step step2.arguments = tuple() step2.keyword_arguments = {} scenario.steps.append(step2) hook_mock = Mock() hook_mock.call.return_value = True runner = Runner(hook_mock) returncode = runner.run_feature(feature) returncode.should.be.equal(1) step1.state.should.be.equal(Step.State.PASSED) step2.state.should.be.equal(Step.State.FAILED) scenario.state.should.be.equal(Step.State.FAILED) feature.state.should.be.equal(Step.State.FAILED)