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_run_debug_step_function_with_exception(debug_or_run, mocker, mock_utils_debugger): """ Test running/debugging a Step which raises an Exception """ # given step = Step( 1, "I am a Step", "foo.feature", 1, parent=None, runable=True, context_class=None, ) step.definition_func = StepHelper.step_fail_func step.argument_match = mocker.MagicMock() step.argument_match.evaluate.return_value = (tuple(), {}) # when method = getattr(step, debug_or_run) state = method() # then assert state == step.state == Step.State.FAILED assert step.failure is not None assert step.failure.reason == "failing step" assert step.failure.name == "AssertionError"
def test_run_debug_step_function_mark_skipped(debug_or_run, mocker, mock_utils_debugger): """ Test running/debugging a Step which marks itself as skipped """ # given step = Step( 1, "I am a Step", "foo.feature", 1, parent=None, runable=True, context_class=None, ) step.definition_func = StepHelper.step_skip_func step.argument_match = mocker.MagicMock() step.argument_match.evaluate.return_value = (tuple(), {}) # when method = getattr(step, debug_or_run) state = method() # then assert state == Step.State.SKIPPED == step.state
def test_run_debug_step_function_with_posargs(debug_or_run, mocker, mock_utils_debugger): """ Test running/debugging a Step with a function and positional arguments """ # mock step function which is to use mocker.spy(StepHelper, "step_func") # given step = Step( 1, "I am a Step", "foo.feature", 1, parent=None, runable=True, context_class=None, ) step.definition_func = StepHelper.step_func step.argument_match = mocker.MagicMock() step.argument_match.evaluate.return_value = ((1, 2), {}) # when method = getattr(step, debug_or_run) state = method() # then assert state == Step.State.PASSED StepHelper.step_func.assert_called_once_with(step, 1, 2)
def test_run_debug_step_function_with_exception( debug_or_run, mocker, mock_utils_debugger ): """ Test running/debugging a Step which raises an Exception """ # given step = Step( 1, "I am a Step", "foo.feature", 1, parent=None, runable=True, context_class=None, ) step.definition_func = StepHelper.step_fail_func step.argument_match = mocker.MagicMock() step.argument_match.evaluate.return_value = (tuple(), {}) # when method = getattr(step, debug_or_run) state = method() # then assert state == step.state == Step.State.FAILED assert step.failure is not None assert step.failure.reason == "failing step" assert step.failure.name == "AssertionError"
def test_run_debug_step_function_mark_skipped( debug_or_run, mocker, mock_utils_debugger ): """ Test running/debugging a Step which marks itself as skipped """ # given step = Step( 1, "I am a Step", "foo.feature", 1, parent=None, runable=True, context_class=None, ) step.definition_func = StepHelper.step_skip_func step.argument_match = mocker.MagicMock() step.argument_match.evaluate.return_value = (tuple(), {}) # when method = getattr(step, debug_or_run) state = method() # then assert state == Step.State.SKIPPED == step.state
def test_run_debug_step_function_with_posargs( debug_or_run, mocker, mock_utils_debugger ): """ Test running/debugging a Step with a function and positional arguments """ # mock step function which is to use mocker.spy(StepHelper, "step_func") # given step = Step( 1, "I am a Step", "foo.feature", 1, parent=None, runable=True, context_class=None, ) step.definition_func = StepHelper.step_func step.argument_match = mocker.MagicMock() step.argument_match.evaluate.return_value = ((1, 2), {}) # when method = getattr(step, debug_or_run) state = method() # then assert state == Step.State.PASSED StepHelper.step_func.assert_called_once_with(step, 1, 2)
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_run_debug_step_function_with_kwargs(debug_or_run, mocker, mock_utils_debugger): """ Test running/debugging a Step with a function and keyword arguments """ # mock step function which is to use mocker.spy(StepHelper, 'step_func') # given step = Step(1, 'I am a Step', 'foo.feature', 1, parent=None, runable=True, context_class=None) step.definition_func = StepHelper.step_func step.argument_match = mocker.MagicMock() step.argument_match.evaluate.return_value = (tuple(), {'foo': '1', 'bar': '2'}) # when method = getattr(step, debug_or_run) state = method() # then assert state == Step.State.PASSED StepHelper.step_func.assert_called_once_with(step, foo='1', bar='2')
def test_running_a_step(self): """ Test running a step """ data = threading.local() data.step_was_called = False def some_step(step): data.step_was_called = True step = Step(1, "Some step", "somefile.feature", 3, None, True) step.definition_func = some_step argument_match_mock = Mock() argument_match_mock.evaluate.return_value = (tuple(), {}) step.argument_match = argument_match_mock hook_mock = Mock() hook_mock.call.return_value = True runner = Runner(hook_mock) returncode = runner.run_step(step) returncode.should.be.equal(0) step.state.should.be.equal(Step.State.PASSED) data.step_was_called.should.be.true