forked from test_framework/pytest-bdd
arguments in when steps when no arguments in givens bug
This commit is contained in:
parent
5492b73322
commit
d9b10a7f79
|
@ -1,6 +1,12 @@
|
|||
Changelog
|
||||
=========
|
||||
|
||||
0.6.1
|
||||
-----
|
||||
|
||||
- Step arguments in whens when there are no given arguments used. (amakhnach, bubenkoff)
|
||||
|
||||
|
||||
0.6.0
|
||||
-----
|
||||
|
||||
|
|
|
@ -65,9 +65,10 @@ def _find_step_function(request, name):
|
|||
lambda: value, fixturedef.scope, fixturedef.params,
|
||||
fixturedef.unittest,
|
||||
)
|
||||
# inject fixture definition
|
||||
request._fixturemanager._arg2fixturedefs[arg] = [fd]
|
||||
if arg in request._funcargs:
|
||||
request._funcargs[arg] = value
|
||||
# inject fixture value in request cache
|
||||
request._funcargs[arg] = value
|
||||
return request.getfuncargvalue(pattern.pattern)
|
||||
raise
|
||||
|
||||
|
|
2
setup.py
2
setup.py
|
@ -6,7 +6,7 @@ from setuptools import setup
|
|||
from setuptools.command.test import test as TestCommand
|
||||
|
||||
|
||||
version = '0.6.0'
|
||||
version = '0.6.1'
|
||||
|
||||
|
||||
class Tox(TestCommand):
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
"""Step arguments tests."""
|
||||
|
||||
import functools
|
||||
import re
|
||||
import pytest
|
||||
from pytest_bdd import scenario, given, when, then
|
||||
|
@ -9,6 +12,10 @@ test_steps = scenario(
|
|||
'Every step takes a parameter with the same name',
|
||||
)
|
||||
|
||||
sc = functools.partial(scenario, 'when_arguments.feature')
|
||||
test_argument_in_when_step_1 = sc('Argument in when, step 1')
|
||||
test_argument_in_when_step_2 = sc('Argument in when, step 2')
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def values():
|
||||
|
@ -25,11 +32,29 @@ def i_pay(euro, values, request):
|
|||
assert euro == values.pop(0)
|
||||
|
||||
|
||||
@given('I have an argument')
|
||||
def argument():
|
||||
"""I have an argument."""
|
||||
return dict(arg=1)
|
||||
|
||||
|
||||
@when(re.compile('I get argument (?P<arg>\d+)'))
|
||||
def get_argument(argument, arg):
|
||||
"""Getting argument."""
|
||||
argument['arg'] = arg
|
||||
|
||||
|
||||
@then(re.compile(r'I should have (?P<euro>\d+) Euro'))
|
||||
def i_should_have(euro, values):
|
||||
assert euro == values.pop(0)
|
||||
|
||||
|
||||
@then(re.compile('My argument should be (?P<arg>\d+)'))
|
||||
def assert_that_my_argument_is_arg(argument, arg):
|
||||
"""Assert that arg from when equals arg."""
|
||||
assert argument['arg'] == arg
|
||||
|
||||
|
||||
def test_multiple_given(request):
|
||||
"""Using the same given fixture raises an error."""
|
||||
test = scenario(
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
Scenario: Argument in when, step 1
|
||||
Given I have an argument
|
||||
|
||||
When I get argument 5
|
||||
|
||||
Then My argument should be 5
|
||||
|
||||
|
||||
Scenario: Argument in when, step 2
|
||||
Given I have an argument
|
||||
|
||||
When I get argument 10
|
||||
|
||||
Then My argument should be 10
|
|
@ -1,7 +1,4 @@
|
|||
"""Test wrong feature syntax."""
|
||||
import functools
|
||||
import re
|
||||
|
||||
import pytest
|
||||
|
||||
from pytest_bdd import scenario, given, when, then
|
||||
|
@ -71,21 +68,3 @@ def test_verbose_output(request):
|
|||
|
||||
assert line_number == 4
|
||||
assert line == 'When I do it again'
|
||||
|
||||
|
||||
sc = functools.partial(scenario, 'failing_arguments.feature')
|
||||
test_argument_in_when_step_1 = sc('Argument in when, step 1')
|
||||
test_argument_in_when_step_2 = sc('Argument in when, step 2')
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@when(re.compile('I get argument (?P<arg>\d+)'))
|
||||
def get_argument(arg):
|
||||
"""Getting argument."""
|
||||
return dict(arg=arg)
|
||||
|
||||
|
||||
@then(re.compile('My argument should be (?P<arg>\d+)'))
|
||||
def assert_that_my_argument_is_arg(get_argument, arg):
|
||||
"""Assert that arg from when equals arg."""
|
||||
assert get_argument['arg'] == arg
|
Loading…
Reference in New Issue