+ docs
This commit is contained in:
Brianna Laugher 2013-05-21 11:12:45 +10:00
parent 3aa0e4a526
commit d8bc40271a
3 changed files with 57 additions and 0 deletions

View File

@ -185,6 +185,29 @@ You can also set a module level marker::
in which case it will be applied to all functions and
methods defined in the module.
.. _`marking individual tests when using parametrize`:
Marking individual tests when using parametrize
-----------------------------------------------
When using parametrize, applying a mark will make it apply
to each individual test. However it is also possible to
apply a marker to an individual test instance::
import pytest
@pytest.mark.foo
@pytest.mark.parametrize(("n", "expected"), [
(1, 2),
pytest.mark.bar((1, 3)),
(2, 3),
])
def test_increment(n, expected):
assert n + 1 == expected
In this example the mark "foo" will apply to each of the three
tests, whereas the "bar" mark is only applied to the second test.
Skip and xfail marks can also be applied in this way, see :ref:`skip/xfail with parametrize`.
.. _`adding a custom marker from a plugin`:

View File

@ -82,6 +82,18 @@ And as usual with test function arguments, you can see the ``input`` and ``outpu
Note that there ways how you can mark a class or a module,
see :ref:`mark`.
It is also possible to mark individual test instances within parametrize::
# content of test_expectation.py
import pytest
@pytest.mark.parametrize(("input", "expected"), [
("3+5", 8),
("2+4", 6),
pytest.mark.xfail(("6*9", 42)),
])
def test_eval(input, expected):
assert eval(input) == expected
.. _`pytest_generate_tests`:

View File

@ -176,6 +176,28 @@ Running it with the report-on-xfail option gives this output::
======================== 6 xfailed in 0.05 seconds =========================
.. _`skip/xfail with parametrize`:
Skip/xfail with parametrize
---------------------------
It is possible to apply markers like skip and xfail to individual
test instances when using parametrize:
import pytest
@pytest.mark.parametrize(("n", "expected"), [
(1, 2),
pytest.mark.xfail((1, 0)),
pytest.mark.xfail(reason="some bug")((1, 3)),
(2, 3),
(3, 4),
(4, 5),
pytest.mark.skipif("sys.version_info >= (3,0)")((10, 11)),
])
def test_increment(n, expected):
assert n + 1 == expected
Imperative xfail from within a test or setup function
------------------------------------------------------