forked from test_framework/pytest-bdd
alias support added
This commit is contained in:
parent
6d6267cc45
commit
c5e6b65466
|
@ -105,8 +105,8 @@ class Feature(object):
|
|||
if mode == GIVEN and prev_mode not in (GIVEN, SCENARIO):
|
||||
raise FeatureError('Given steps must be the first in withing the Scenario')
|
||||
|
||||
if mode == WHEN and prev_mode not in (GIVEN, WHEN):
|
||||
raise FeatureError('When steps must follow Given steps')
|
||||
if mode == WHEN and prev_mode not in (SCENARIO, GIVEN, WHEN):
|
||||
raise FeatureError('When steps must first or follow Given steps')
|
||||
|
||||
if mode == THEN and prev_mode not in (WHEN, THEN):
|
||||
raise FeatureError('Then steps must follow When steps')
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
Scenario: Multiple decorated aliases should work
|
||||
Given I have an empty list
|
||||
And I have foo (which is 1) in my list
|
||||
And I have bar (alias of foo) in my list
|
||||
When I do crash (which is 2)
|
||||
And I do boom (alias of crash)
|
||||
Then my list should be [1, 2, 2]
|
|
@ -6,3 +6,8 @@ Scenario: Executed step by step
|
|||
And I append 3 to the list
|
||||
Then foo should have value "foo"
|
||||
And the list should be [1, 2, 3]
|
||||
|
||||
|
||||
Scenario: When step can be the first
|
||||
When I do nothing
|
||||
Then I make no mistakes
|
|
@ -0,0 +1,29 @@
|
|||
"""Test step alias when decorated multiple times."""
|
||||
|
||||
from pytest_bdd import scenario, given, when, then
|
||||
|
||||
|
||||
test_steps = scenario('alias.feature', 'Multiple decorated aliases should work')
|
||||
|
||||
|
||||
@given('Given I have an empty list')
|
||||
def results():
|
||||
return []
|
||||
|
||||
|
||||
@given('I have foo (which is 1) in my list')
|
||||
@given('I have bar (alias of foo) in my list')
|
||||
def foo(results):
|
||||
results.append(1)
|
||||
|
||||
|
||||
@when('I do crash (which is 2)')
|
||||
@when('I do boom (alias of crash)')
|
||||
def crash(results):
|
||||
results.append(2)
|
||||
|
||||
|
||||
@then('my list should be [1, 2, 2]')
|
||||
def check_results(results):
|
||||
"""Fixture is evaluated only once, so the list will be [1, 2, 2]"""
|
||||
assert results == [1, 2, 2]
|
|
@ -37,3 +37,16 @@ def foo_is_foo(foo):
|
|||
@then('the list should be [1, 2, 3]')
|
||||
def check_results(results):
|
||||
assert results == [1, 2, 3]
|
||||
|
||||
|
||||
test_when_first = scenario('steps.feature', 'When step can be the first')
|
||||
|
||||
|
||||
@when('When I do nothing')
|
||||
def do_nothing():
|
||||
pass
|
||||
|
||||
|
||||
@then('Then I make no mistakes')
|
||||
def no_errors():
|
||||
assert True
|
||||
|
|
|
@ -9,7 +9,6 @@ from pytest_bdd.feature import FeatureError
|
|||
@pytest.fixture(params=[
|
||||
'When after then',
|
||||
'Then first',
|
||||
'When first',
|
||||
'Given after When',
|
||||
'Given after Then',
|
||||
])
|
||||
|
|
|
@ -10,10 +10,6 @@ Scenario: Then first
|
|||
Then it won't work
|
||||
|
||||
|
||||
Scenario: When first
|
||||
When it won't work
|
||||
|
||||
|
||||
Scenario: Given after When
|
||||
Given something
|
||||
When something else
|
||||
|
|
Loading…
Reference in New Issue