diff --git a/doc/en/example/parametrize.rst b/doc/en/example/parametrize.rst index 7a9992ca7..bb286b472 100644 --- a/doc/en/example/parametrize.rst +++ b/doc/en/example/parametrize.rst @@ -116,6 +116,15 @@ the argument name:: diff = a - b assert diff == expected + @pytest.mark.parametrize("a,b,expected", [ + pytest.param(datetime(2001, 12, 12), datetime(2001, 12, 11), + timedelta(1), id='forward'), + pytest.param(datetime(2001, 12, 11), datetime(2001, 12, 12), + timedelta(-1), id='backward'), + ]) + def test_timedistance_v3(a, b, expected): + diff = a - b + assert diff == expected In ``test_timedistance_v0``, we let pytest generate the test IDs. @@ -132,7 +141,7 @@ objects, they are still using the default pytest representation:: ======= test session starts ======== platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y rootdir: $REGENDOC_TMPDIR, inifile: - collected 6 items + collected 8 items @@ -140,9 +149,14 @@ objects, they are still using the default pytest representation:: + + ======= no tests ran in 0.12 seconds ======== +In ``test_timedistance_v3``, we used ``pytest.param`` to specify the test IDs +together with the actual data, instead of listing them separately. + A quick port of "testscenarios" ------------------------------------