Description
// enhancement idea
// this might already exist, tried to find it, failed
tldr; I want my xfail'ed tests to cause test suite to fail if they succeed
Hey,
Often I find myself tests that given an two set outputs, sometimes return a value and sometimes raise specific exceptions. I'm currently splitting this in two separate tests, one for "good" values, one for exceptions, and use pytest.raises
.
Inspired by docs on parametrizing tests I thought I could use mark.xfail to group these tests in one logical thing.
However, I don't like XPASS's - I'd like to be able to say that these tests have to fail with specific exceptions.
It would basically be a shorthand for splitting a test into two and using pytest.raises
.
Ideally, it would work as an extra argument to xfail (strict=True?), rather than command line option, because I cannot set the value globally.
Basically, I'd like this to fail:
import pytest
def complicated_validation_function(input_data):
if input_data in ('should_raise', 'should_raise_too_but_i_made_a_typo'):
raise ValueError
return True
@pytest.mark.parametrize('input_data', [
(0),
pytest.mark.xfail('should_raise'),
pytest.mark.xfail('should_raise_too'),
])
def test_validation(input_data):
assert complicated_validation_function(input_data) is True
Does this already exist somewhere?
If not, does this sound like a plausible idea?
edit: I dunno how to mark this as proposal per contributing guidelines