diff --git a/doc/en/example/parametrize.rst b/doc/en/example/parametrize.rst index 81092789a..feb78ff8d 100644 --- a/doc/en/example/parametrize.rst +++ b/doc/en/example/parametrize.rst @@ -83,35 +83,38 @@ the argument name:: # content of test_time.py + import pytest + from datetime import datetime, timedelta - testdata = [(datetime(2001, 12, 12), datetime(2001, 12, 11), timedelta(1)), - (datetime(2001, 12, 11), datetime(2001, 12, 12), timedelta(-1)), - ] + testdata = [ + (datetime(2001, 12, 12), datetime(2001, 12, 11), timedelta(1)), + (datetime(2001, 12, 11), datetime(2001, 12, 12), timedelta(-1)), + ] @pytest.mark.parametrize("a,b,expected", testdata) def test_timedistance_v0(a, b, expected): - diff = a - b - assert diff == expected + diff = a - b + assert diff == expected @pytest.mark.parametrize("a,b,expected", testdata, ids=["forward", "backward"]) def test_timedistance_v1(a, b, expected): - diff = a - b - assert diff == expected + diff = a - b + assert diff == expected def idfn(val): - if isinstance(val, (datetime,)): - # note this wouldn't show any hours/minutes/seconds - return val.strftime('%Y%m%d') + if isinstance(val, (datetime,)): + # note this wouldn't show any hours/minutes/seconds + return val.strftime('%Y%m%d') @pytest.mark.parametrize("a,b,expected", testdata, ids=idfn) def test_timedistance_v2(a, b, expected): - diff = a - b - assert diff == expected + diff = a - b + assert diff == expected In ``test_timedistance_v0``, we let pytest generate the test IDs. @@ -127,21 +130,18 @@ objects, they are still using the default pytest representation:: $ py.test test_time.py --collect-only ======= test session starts ======== - platform linux -- Python 3.4.2, pytest-2.8.1.dev1, py-1.4.30, pluggy-0.3.1 + platform linux -- Python 3.4.3, pytest-2.8.1.dev1, py-1.4.30, pluggy-0.3.1 rootdir: $REGENDOC_TMPDIR, inifile: - collected 0 items / 1 errors + collected 6 items + + + + + + + - ======= ERRORS ======== - _______ ERROR collecting test_time.py ________ - $PYTHON_PREFIX/lib/python3.4/site-packages/_pytest/python.py:581: in _importtestmodule - mod = self.fspath.pyimport(ensuresyspath=importmode) - $PYTHON_PREFIX/lib/python3.4/site-packages/py/_path/local.py:650: in pyimport - __import__(modname) - E File "$REGENDOC_TMPDIR/test_time.py", line 5 - E (datetime(2001, 12, 11), datetime(2001, 12, 12), timedelta(-1)), - E ^ - E SyntaxError: unexpected EOF while parsing - ======= 1 error in 0.12 seconds ======== + ======= in 0.12 seconds ======== A quick port of "testscenarios" ------------------------------------