step arguments in progress
This commit is contained in:
parent
eeb9f9afc0
commit
000f8f764a
|
@ -40,7 +40,22 @@ def _find_step_function(request, name):
|
|||
try:
|
||||
return request.getfuncargvalue(name)
|
||||
except python.FixtureLookupError:
|
||||
pass
|
||||
fm = request._fixturemanager
|
||||
for fixturename, fixturedef in fm._arg2fixturedefs.items():
|
||||
fixturedef = fixturedef[0]
|
||||
pattern = getattr(fixturedef.func, 'pattern', None)
|
||||
if pattern:
|
||||
m = pattern.match(name)
|
||||
if m:
|
||||
for name, value in m.groupdict().items():
|
||||
fd = python.FixtureDef(
|
||||
fm, fixturedef.baseid, name, lambda: value, fixturedef.scope, fixturedef.params,
|
||||
fixturedef.unittest)
|
||||
fm._arg2fixturedefs[name] = [fd]
|
||||
if name in request._funcargs:
|
||||
request._funcargs[name] = value
|
||||
return request.getfuncargvalue(pattern.pattern)
|
||||
raise
|
||||
|
||||
|
||||
def scenario(feature_name, scenario_name):
|
||||
|
|
|
@ -113,10 +113,10 @@ def _parse_step_name(name):
|
|||
|
||||
"""
|
||||
if isinstance(name, RE_TYPE):
|
||||
name = remove_prefix(name.pattern)
|
||||
name = name.pattern
|
||||
return name, re.compile(name)
|
||||
else:
|
||||
return remove_prefix(name), None
|
||||
return name, None
|
||||
|
||||
|
||||
def _contribute_regex_pattern(func, pattern):
|
||||
|
@ -131,9 +131,6 @@ def _contribute_regex_pattern(func, pattern):
|
|||
:raise: StepError if the function doesn't take group names as parameters.
|
||||
|
||||
"""
|
||||
unknown = set(pattern.groupindex) - set(inspect.getargspec(func).args)
|
||||
if unknown:
|
||||
raise StepError('Step function should take parameters: {0}'.format([unicode(x) for x in unknown]))
|
||||
func.pattern = pattern
|
||||
|
||||
|
||||
|
@ -156,9 +153,6 @@ def _step_decorator(step_type, step_name):
|
|||
def decorator(func):
|
||||
# Validate the regex arguments and their group names
|
||||
# Contribute the regex pattern to the step function
|
||||
if pattern:
|
||||
_contribute_regex_pattern(func, pattern)
|
||||
|
||||
step_func = func
|
||||
|
||||
if step_type == GIVEN:
|
||||
|
@ -177,6 +171,9 @@ def _step_decorator(step_type, step_name):
|
|||
# Preserve a docstring
|
||||
lazy_step_func.__doc__ = func.__doc__
|
||||
|
||||
if pattern:
|
||||
_contribute_regex_pattern(lazy_step_func, pattern)
|
||||
|
||||
contribute_to_module(
|
||||
get_caller_module(),
|
||||
step_name,
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
Scenario: Executed with steps matching regex step definitons
|
||||
Given I have a foo fixture with value "foo"
|
||||
And there is a list
|
||||
|
||||
When I append 1 to the list
|
||||
And I append 2 to the list
|
||||
And I append 3 to the list
|
||||
|
||||
Then foo should have value "foo"
|
||||
And the list should be [1, 2, 3]
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import re
|
||||
from pytest_bdd import scenario, given, when, then
|
||||
|
||||
|
||||
|
@ -14,7 +15,7 @@ def results():
|
|||
return []
|
||||
|
||||
|
||||
@when('I append (?P<n>\d+) to the list')
|
||||
@when(re.compile('I append (?P<n>\d+) to the list'))
|
||||
def append_to_list(results, n):
|
||||
results.append(int(n))
|
||||
|
||||
|
|
Loading…
Reference in New Issue