mark plugin: move the unclean marked parameter extraction

This commit is contained in:
Ronny Pfannschmidt 2016-08-21 20:44:37 +02:00
parent abe8f5e23f
commit 406777d104
2 changed files with 28 additions and 18 deletions

View File

@ -283,6 +283,21 @@ class MarkDecorator:
return self.__class__(self.name, args=args, kwargs=kw) return self.__class__(self.name, args=args, kwargs=kw)
def extract_argvalue(maybe_marked_args):
# TODO: incorrect mark data, the old code wanst able to collect lists
# individual parametrized argument sets can be wrapped in a series
# of markers in which case we unwrap the values and apply the mark
# at Function init
newmarks = {}
argval = maybe_marked_args
while isinstance(argval, MarkDecorator):
newmark = MarkDecorator(argval.markname,
argval.args[:-1], argval.kwargs)
newmarks[newmark.markname] = newmark
argval = argval.args[-1]
return argval, newmarks
class MarkInfo: class MarkInfo:
""" Marking object created by :class:`MarkDecorator` instances. """ """ Marking object created by :class:`MarkDecorator` instances. """
def __init__(self, name, args, kwargs): def __init__(self, name, args, kwargs):

View File

@ -5,10 +5,11 @@ import inspect
import sys import sys
import collections import collections
import math import math
from itertools import count
import py import py
import pytest import pytest
from _pytest.mark import MarkDecorator, MarkerError from _pytest.mark import MarkerError
import _pytest import _pytest
@ -776,19 +777,14 @@ class Metafunc(fixtures.FuncargnamesCompatAttr):
to set a dynamic scope using test context or configuration. to set a dynamic scope using test context or configuration.
""" """
from _pytest.fixtures import scopes from _pytest.fixtures import scopes
# individual parametrized argument sets can be wrapped in a series from _pytest.mark import extract_argvalue
# of markers in which case we unwrap the values and apply the mark
# at Function init
newkeywords = {}
unwrapped_argvalues = [] unwrapped_argvalues = []
for i, argval in enumerate(argvalues): newkeywords = []
while isinstance(argval, MarkDecorator): for maybe_marked_args in argvalues:
newmark = MarkDecorator(argval.markname, argval, newmarks = extract_argvalue(maybe_marked_args)
argval.args[:-1], argval.kwargs)
newmarks = newkeywords.setdefault(i, {})
newmarks[newmark.markname] = newmark
argval = argval.args[-1]
unwrapped_argvalues.append(argval) unwrapped_argvalues.append(argval)
newkeywords.append(newmarks)
argvalues = unwrapped_argvalues argvalues = unwrapped_argvalues
if not isinstance(argnames, (tuple, list)): if not isinstance(argnames, (tuple, list)):
@ -803,8 +799,7 @@ class Metafunc(fixtures.FuncargnamesCompatAttr):
newmark = pytest.mark.skip( newmark = pytest.mark.skip(
reason="got empty parameter set %r, function %s at %s:%d" % ( reason="got empty parameter set %r, function %s at %s:%d" % (
argnames, self.function.__name__, fs, lineno)) argnames, self.function.__name__, fs, lineno))
newmarks = newkeywords.setdefault(0, {}) newkeywords = [{newmark.markname: newmark}]
newmarks[newmark.markname] = newmark
if scope is None: if scope is None:
if self._arg2fixturedefs: if self._arg2fixturedefs:
@ -848,12 +843,12 @@ class Metafunc(fixtures.FuncargnamesCompatAttr):
ids = idmaker(argnames, argvalues, idfn, ids, self.config) ids = idmaker(argnames, argvalues, idfn, ids, self.config)
newcalls = [] newcalls = []
for callspec in self._calls or [CallSpec2(self)]: for callspec in self._calls or [CallSpec2(self)]:
for param_index, valset in enumerate(argvalues): elements = zip(ids, argvalues, newkeywords, count())
for a_id, valset, keywords, param_index in elements:
assert len(valset) == len(argnames) assert len(valset) == len(argnames)
newcallspec = callspec.copy(self) newcallspec = callspec.copy(self)
newcallspec.setmulti(valtypes, argnames, valset, ids[param_index], newcallspec.setmulti(valtypes, argnames, valset, a_id,
newkeywords.get(param_index, {}), scopenum, keywords, scopenum, param_index)
param_index)
newcalls.append(newcallspec) newcalls.append(newcallspec)
self._calls = newcalls self._calls = newcalls