Use std_warn for warning about applying marks directly to parameters

This commit is contained in:
Bruno Oliveira 2018-08-30 21:09:39 -03:00
parent 0100f61b62
commit 8e4501ee29
4 changed files with 17 additions and 9 deletions

View File

@ -65,7 +65,7 @@ class ParameterSet(namedtuple("ParameterSet", "values, marks, id")):
return cls(values, marks, id_) return cls(values, marks, id_)
@classmethod @classmethod
def extract_from(cls, parameterset, legacy_force_tuple=False): def extract_from(cls, parameterset, legacy_force_tuple=False, item=None):
""" """
:param parameterset: :param parameterset:
a legacy style parameterset that may or may not be a tuple, a legacy style parameterset that may or may not be a tuple,
@ -75,6 +75,7 @@ class ParameterSet(namedtuple("ParameterSet", "values, marks, id")):
enforce tuple wrapping so single argument tuple values enforce tuple wrapping so single argument tuple values
don't get decomposed and break tests don't get decomposed and break tests
:param item: the item that we will be extracting the parameters from.
""" """
if isinstance(parameterset, cls): if isinstance(parameterset, cls):
@ -94,19 +95,21 @@ class ParameterSet(namedtuple("ParameterSet", "values, marks, id")):
argval = (argval,) argval = (argval,)
if newmarks: if newmarks:
warnings.warn(MARK_PARAMETERSET_UNPACKING) item.std_warn(MARK_PARAMETERSET_UNPACKING)
return cls(argval, marks=newmarks, id=None) return cls(argval, marks=newmarks, id=None)
@classmethod @classmethod
def _for_parametrize(cls, argnames, argvalues, func, config): def _for_parametrize(cls, argnames, argvalues, func, config, function_definition):
if not isinstance(argnames, (tuple, list)): if not isinstance(argnames, (tuple, list)):
argnames = [x.strip() for x in argnames.split(",") if x.strip()] argnames = [x.strip() for x in argnames.split(",") if x.strip()]
force_tuple = len(argnames) == 1 force_tuple = len(argnames) == 1
else: else:
force_tuple = False force_tuple = False
parameters = [ parameters = [
ParameterSet.extract_from(x, legacy_force_tuple=force_tuple) ParameterSet.extract_from(
x, legacy_force_tuple=force_tuple, item=function_definition
)
for x in argvalues for x in argvalues
] ]
del argvalues del argvalues

View File

@ -326,7 +326,7 @@ def get_fslocation_from_item(item):
""" """
result = getattr(item, "location", None) result = getattr(item, "location", None)
if result is not None: if result is not None:
return result return result[:2]
obj = getattr(item, "obj", None) obj = getattr(item, "obj", None)
if obj is not None: if obj is not None:
return getfslineno(obj) return getfslineno(obj)

View File

@ -967,7 +967,11 @@ class Metafunc(fixtures.FuncargnamesCompatAttr):
from _pytest.mark import ParameterSet from _pytest.mark import ParameterSet
argnames, parameters = ParameterSet._for_parametrize( argnames, parameters = ParameterSet._for_parametrize(
argnames, argvalues, self.function, self.config argnames,
argvalues,
self.function,
self.config,
function_definition=self.definition,
) )
del argvalues del argvalues

View File

@ -18,7 +18,9 @@ from _pytest.capture import CaptureManager
from _pytest.main import EXIT_NOTESTSCOLLECTED from _pytest.main import EXIT_NOTESTSCOLLECTED
needsosdup = pytest.mark.xfail("not hasattr(os, 'dup')") needsosdup = pytest.mark.skipif(
not hasattr(os, "dup"), reason="test needs os.dup, not available on this platform"
)
def tobytes(obj): def tobytes(obj):
@ -61,9 +63,8 @@ class TestCaptureManager(object):
pytest_addoption(parser) pytest_addoption(parser)
assert parser._groups[0].options[0].default == "sys" assert parser._groups[0].options[0].default == "sys"
@needsosdup
@pytest.mark.parametrize( @pytest.mark.parametrize(
"method", ["no", "sys", pytest.mark.skipif('not hasattr(os, "dup")', "fd")] "method", ["no", "sys", pytest.param("fd", marks=needsosdup)]
) )
def test_capturing_basic_api(self, method): def test_capturing_basic_api(self, method):
capouter = StdCaptureFD() capouter = StdCaptureFD()