I'm quite new to pytest and I would like to know how to mark a test as "expected to fail" when called with certain parameters. I parametrize test like this:
@pytest.mark.parametrize("param1", [False, True])
@pytest.mark.parametrize("param2", [1, 2, 3])
def test_foo(self, param1, param2):
...
What I'm trying to achieve is that when the test is called with (param1 == True and param2 == 2)
, the test should fail; whilst any other parameter combinations should pass.
But I haven't found any way to do this. Do you have any ideas?
Custom marker and command line option to control test runs. The --markers option always gives you a list of available markers: $ pytest --markers @pytest. mark.
you can put @pytest. mark. parametrize style parametrization on the test functions to parametrize input/output values as well.
pytest. fixture() allows one to parametrize fixture functions.
See xfail with parametrize:
@pytest.mark.parametrize("param2, param2", [
(1, True),
(2, True),
pytest.param(1, False, marks=pytest.mark.xfail(reason='some bug')),
])
def test_foo(self, param1, param2):
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With