forked from test_framework/pytest-bdd
wrong order tests
This commit is contained in:
parent
c7957e694a
commit
f6837b948c
|
@ -30,6 +30,7 @@ from pytest_bdd.types import SCENARIO, GIVEN, WHEN, THEN # pragma: no cover
|
|||
|
||||
class FeatureError(Exception): # pragma: no cover
|
||||
"""Feature parse error."""
|
||||
|
||||
message = u'{0}.\nLine number: {1}.\nLine: {2}.'
|
||||
|
||||
def __str__(self):
|
||||
|
|
|
@ -108,7 +108,9 @@ def scenario(feature_name, scenario_name):
|
|||
|
||||
# Check the step types are called in the correct order
|
||||
if step_func.step_type != step_type:
|
||||
raise StepTypeError('Wrong step type "{0}", expected {1}.'.format(step_func.step_type, step_type))
|
||||
raise StepTypeError(
|
||||
'Wrong step type "{0}" while "{1}" is expected.'.format(step_func.step_type, step_type)
|
||||
)
|
||||
|
||||
# Check if the fixture that implements given step has not been yet used by another given step
|
||||
if step_type == GIVEN:
|
||||
|
|
|
@ -2,25 +2,60 @@
|
|||
|
||||
import pytest
|
||||
|
||||
from pytest_bdd import scenario
|
||||
from pytest_bdd import scenario, given, when, then
|
||||
from pytest_bdd.feature import FeatureError
|
||||
from pytest_bdd.scenario import StepTypeError
|
||||
|
||||
|
||||
@pytest.fixture(params=[
|
||||
'When after then',
|
||||
'Then first',
|
||||
'Given after When',
|
||||
'Given after Then',
|
||||
])
|
||||
def scenario_name(request):
|
||||
return request.param
|
||||
@given('something')
|
||||
def given_something():
|
||||
pass
|
||||
|
||||
|
||||
def test_wrong(request, scenario_name):
|
||||
@when('something else')
|
||||
def when_something_else():
|
||||
pass
|
||||
|
||||
|
||||
@then('nevermind')
|
||||
def then_nevermind():
|
||||
pass
|
||||
|
||||
|
||||
# @pytest.mark.parametrize(
|
||||
# ('feature', 'scenario_name'),
|
||||
# [
|
||||
# # ('wrong.feature', 'When after then'),
|
||||
# # ('wrong.feature', 'Then first'),
|
||||
# # ('wrong.feature', 'Given after When'),
|
||||
# # ('wrong.feature', 'Given after Then'),
|
||||
# ]
|
||||
# )
|
||||
# def test_wrong(request, feature, scenario_name):
|
||||
# """Test wrong feature scenarios."""
|
||||
|
||||
# sc = scenario(feature, scenario_name)
|
||||
# sc(request)
|
||||
# with pytest.raises(FeatureError):
|
||||
# sc(request)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'scenario_name',
|
||||
[
|
||||
'When in Given',
|
||||
'When in Then',
|
||||
'Then in Given',
|
||||
'Given in When',
|
||||
'Given in Then',
|
||||
'Then in When',
|
||||
]
|
||||
)
|
||||
def test_wrong_type_order(request, scenario_name):
|
||||
"""Test wrong feature scenarios."""
|
||||
|
||||
sc = scenario('wrong.feature', scenario_name)
|
||||
with pytest.raises(FeatureError):
|
||||
sc = scenario('wrong_type_order.feature', scenario_name)
|
||||
with pytest.raises(StepTypeError):
|
||||
sc(request)
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
Scenario: When in Given
|
||||
Given something else
|
||||
|
||||
|
||||
Scenario: When in Then
|
||||
When something else
|
||||
Then something else
|
||||
|
||||
|
||||
Scenario: Then in Given
|
||||
Given nevermind
|
||||
|
||||
|
||||
Scenario: Given in When
|
||||
When something
|
||||
|
||||
|
||||
Scenario: Given in Then
|
||||
When something else
|
||||
Then something
|
||||
|
||||
|
||||
Scenario: Then in When
|
||||
When nevermind
|
Loading…
Reference in New Issue