Source

pytest-patches / parametrize-items

Full commit
# HG changeset patch
# Parent 3da8cec6c5326ed27c144c9b6d7a64a648370005
introduce items kwarg for parametrize  which provides (ids, argvalues) = zip(items)

diff --git a/_pytest/python.py b/_pytest/python.py
--- a/_pytest/python.py
+++ b/_pytest/python.py
@@ -589,7 +589,7 @@ class Metafunc:
         self._calls = []
         self._ids = py.builtin.set()
 
-    def parametrize(self, argnames, argvalues, indirect=False, ids=None):
+    def parametrize(self, argnames, argvalues=None, indirect=False, ids=None, items=None):
         """ Add new invocations to the underlying test function using the list
         of argvalues for the given argnames.  Parametrization is performed
         during the collection phase.  If you need to setup expensive resources
@@ -609,7 +609,15 @@ class Metafunc:
         :arg ids: list of string ids each corresponding to the argvalues so
             that they are part of the test id. If no ids are provided they will
             be generated automatically from the argvalues.
+        :arg items: ids, argvalues = zip(items)
         """
+        if items is None:
+            assert argvalues is not None
+        else:
+            assert argvalues is None and ids is None
+
+            ids, argvalues = zip(*items)
+
         if not isinstance(argnames, (tuple, list)):
             argnames = (argnames,)
             argvalues = [(val,) for val in argvalues]
diff --git a/testing/test_python.py b/testing/test_python.py
--- a/testing/test_python.py
+++ b/testing/test_python.py
@@ -1048,6 +1048,15 @@ class TestMetafunc:
         assert metafunc._calls[1].funcargs == dict(x=3, y=4)
         assert metafunc._calls[1].id == "3-4"
 
+    def test_parametrize_items(self):
+        metafunc = funcargs.Metafunc(lambda x,y: None)
+        metafunc.parametrize(('x', 'y'), items=[('small', (1,2)), ('big', (3,4))])
+        assert metafunc._calls[0].id == 'small'
+        assert metafunc._calls[0].funcargs == dict(x=1, y=2)
+        assert metafunc._calls[1].id == 'big'
+        assert metafunc._calls[1].funcargs == dict(x=3, y=4)
+
+
 class TestMetafuncFunctional:
     def test_attributes(self, testdir):
         p = testdir.makepyfile("""