address some comments by @hpk42 on 0b9d82e :

- move tests into their own class, rename
- add test showing metafunc.parametrize called in pytest_generate_tests rather than as decorator
- add test and fix single-argname case
- convert two loops into one in parametrize()

also
- renamed 'input' to 'n', since 'input' is a built-in
This commit is contained in:
Brianna Laugher
2013-05-20 12:52:20 +10:00
parent 5373a63008
commit ee65ca10f4
2 changed files with 88 additions and 73 deletions

View File

@@ -671,24 +671,27 @@ class Metafunc(FuncargnamesCompatAttr):
It will also override any fixture-function defined scope, allowing
to set a dynamic scope using test context or configuration.
"""
# remove any marks applied to individual tests instances
# these marks will be applied in Function init
newkeywords = {}
strippedargvalues = []
for i, argval in enumerate(argvalues):
if isinstance(argval, MarkDecorator):
# convert into a mark without the test content mixed in
newmark = MarkDecorator(argval.markname, argval.args[:-1], argval.kwargs)
newkeywords[i] = {newmark.markname: newmark}
strippedargvalues.append(argval.args[-1])
else:
newkeywords[i] = {}
strippedargvalues.append(argval)
argvalues = strippedargvalues
if not isinstance(argnames, (tuple, list)):
argnames = (argnames,)
argvalues = [(val,) for val in argvalues]
if not argvalues:
argvalues = [(_notexists,) * len(argnames)]
# these marks/keywords will be applied in Function init
newkeywords = {}
for i, argval in enumerate(argvalues):
newkeywords[i] = {}
if isinstance(argval, MarkDecorator):
# convert into a mark without the test content mixed in
newmark = MarkDecorator(argval.markname, argval.args[:-1], argval.kwargs)
newkeywords[i] = {newmark.markname: newmark}
argvalues = [av.args[-1] if isinstance(av, MarkDecorator) else av
for av in argvalues]
if scope is None:
scope = "subfunction"
scopenum = scopes.index(scope)