[pytest-dev] Issue mixing skipif and parametrize
Bruno Oliveira
nicoddemus at gmail.com
Mon Mar 13 20:59:54 EDT 2017
On Mon, Mar 13, 2017 at 9:48 PM Lele Gaifax lele at metapensiero.it
<http://mailto:lele@metapensiero.it> wrote:
> The only thing I couldn't figure out is how I can report back some kind of
> "skipped" message, some kind of XFailed status without breaking off the
> generation loop (see line 69)...
>
parametrize is the same call executed by pytest.mark.parametrize, so all
you have to do is wrap the values you want to skip in a pytest.mark.skip()
decorator:
import pytest
def pytest_generate_tests(metafunc):
metafunc.parametrize('x', [0, pytest.mark.skip(1)(reason='reasons'), 2])
def test_foo(x):
pass
Here we are parametrizing with [0, 1, 2], but skipping 1. This outputs:
pytest .tmp\foo.py -q
.s.
=========================== short test summary info ===========================
SKIP [1] .tmp\foo.py:7: reasons
2 passed, 1 skipped in 0.01 seconds
More info here:
http://doc.pytest.org/en/latest/parametrize.html?highlight=parametrize#pytest-mark-parametrize-parametrizing-test-functions
Cheers,
Bruno.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pytest-dev/attachments/20170314/55292e08/attachment.html>
More information about the pytest-dev
mailing list