From 8a0a18e9b369f758b7114b524f097ee69e75e1a3 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Wed, 22 May 2013 15:24:58 +0200 Subject: [PATCH] - add Brianna (@pfctdayelise ) to changelog and contributors - fix some broken tests on py32/py33 (related to issue308 merge) - re-format docstrings - --- AUTHORS | 1 + CHANGELOG | 3 +++ _pytest/python.py | 33 +++++++++++++++++---------------- testing/python/metafunc.py | 6 +++--- tox.ini | 2 +- 5 files changed, 25 insertions(+), 20 deletions(-) diff --git a/AUTHORS b/AUTHORS index 6e4f7714f..8cfa17f00 100644 --- a/AUTHORS +++ b/AUTHORS @@ -8,6 +8,7 @@ Benjamin Peterson Floris Bruynooghe Jason R. Coombs Samuele Pedroni +Brianna Laugher Carl Friedrich Bolz Armin Rigo Maho diff --git a/CHANGELOG b/CHANGELOG index 52feb271f..d561c8088 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,9 @@ Changes between 2.3.5 and 2.4.DEV ----------------------------------- +- fix issue 308 - allow to mark/xfail/skip individual parameter sets + when parametrizing. Thanks Brianna Laugher. + - (experimental) allow fixture functions to be implemented as context managers. Thanks Andreas Pelme, Vladimir Keleshev. diff --git a/_pytest/python.py b/_pytest/python.py index eab5ce8e6..1327fe1af 100644 --- a/_pytest/python.py +++ b/_pytest/python.py @@ -651,11 +651,12 @@ class Metafunc(FuncargnamesCompatAttr): :arg argnames: an argument name or a list of argument names - :arg argvalues: The list of argvalues determines how often a test is invoked - with different argument values. If only one argname was specified argvalues - is a list of simple values. If N argnames were specified, argvalues must - be a list of N-tuples, where each tuple-element specifies a value for its - respective argname. + :arg argvalues: The list of argvalues determines how often a + test is invoked with different argument values. If only one + argname was specified argvalues is a list of simple values. If N + argnames were specified, argvalues must be a list of N-tuples, + where each tuple-element specifies a value for its respective + argname. :arg indirect: if True each argvalue corresponding to an argname will be passed as request.param to its respective argname fixture @@ -671,20 +672,20 @@ 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 + + # individual parametrized argument sets can be wrapped in a + # marker in which case we unwrap the values and apply the mark + # at Function init newkeywords = {} - strippedargvalues = [] + unwrapped_argvalues = [] 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) + 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 + argval = argval.args[-1] + unwrapped_argvalues.append(argval) + argvalues = unwrapped_argvalues if not isinstance(argnames, (tuple, list)): argnames = (argnames,) @@ -710,7 +711,7 @@ class Metafunc(FuncargnamesCompatAttr): assert len(valset) == len(argnames) newcallspec = callspec.copy(self) newcallspec.setmulti(valtype, argnames, valset, ids[i], - newkeywords[i], scopenum) + newkeywords.get(i, {}), scopenum) newcalls.append(newcallspec) self._calls = newcalls diff --git a/testing/python/metafunc.py b/testing/python/metafunc.py index 786446637..ccc1b2f22 100644 --- a/testing/python/metafunc.py +++ b/testing/python/metafunc.py @@ -578,8 +578,8 @@ class TestMetafuncFunctional: ]) -@pytest.mark.issue308 class TestMarkersWithParametrization: + pytestmark = pytest.mark.issue308 def test_simple_mark(self, testdir): s = """ import pytest @@ -680,7 +680,7 @@ class TestMarkersWithParametrization: @pytest.mark.parametrize(("n", "expected"), [ (1, 2), - pytest.mark.xfail("sys.version > 0")((1, 3)), + pytest.mark.xfail("True")((1, 3)), (2, 3), ]) def test_increment(n, expected): @@ -712,7 +712,7 @@ class TestMarkersWithParametrization: @pytest.mark.parametrize(("n", "expected"), [ (1, 2), - pytest.mark.xfail("sys.version > 0", reason="some bug")((1, 3)), + pytest.mark.xfail("True", reason="some bug")((1, 3)), (2, 3), ]) def test_increment(n, expected): diff --git a/tox.ini b/tox.ini index 98c295fde..3af69e880 100644 --- a/tox.ini +++ b/tox.ini @@ -31,7 +31,7 @@ setenv= PYTHONDONTWRITEBYTECODE=1 commands= py.test -n3 -rfsxX \ - --junitxml={envlogdir}/junit-{envname}.xml [] + --junitxml={envlogdir}/junit-{envname}.xml {posargs:testing} [testenv:trial] changedir=.