def test_run_step_with_keyword_arguments_passed(self): """ Test running a passing step with keyword arguments """ data = threading.local() data.step_was_run = False data.number = None data.string = None def step_passed(step, number, string): data.step_was_run = True data.number = int(number) data.string = string step = Step(1, "I call a passing step with string argument 'Tschau' and number argument 42", "somefile.feature", 3, None, True) step.definition_func = step_passed match = re.search("I call a passing step with string argument '(?P<string>.*?)' and number argument (?P<number>\d+)", step.sentence) step.arguments = match.groups() step.keyword_arguments = match.groupdict() step.state.should.be.equal(Step.State.UNTESTED) step.run.when.called_with().should.return_value(Step.State.PASSED) data.step_was_run.should.be.true data.number.should.be.equal(42) data.string.should.be.equal("Tschau")
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_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)
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 step.arguments = tuple() step.keyword_arguments = {} 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