Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runtime Strict xfail #4216

Closed
jbrockmendel opened this issue Oct 23, 2018 · 2 comments
Closed

Runtime Strict xfail #4216

jbrockmendel opened this issue Oct 23, 2018 · 2 comments
Labels
type: question general question, might be closed after 2 weeks of inactivity

Comments

@jbrockmendel
Copy link

I frequently have to xfail one case out of a whole bunch of parametrized test cases, e.g.:

@pytest.mark.parametrize('box', [pd.Index, pd.Series, pd.DataFrame])
@pytest.mark.parametrize('other', [3.14, np.float64(3.14), np.array([3.14])])
@pytest.mark.parametrize('moon', ["Full", "New", "Blue"])
def test_thing(self, box, other, moon):
    if box is pd.DataFrame and isinstance(other, np.ndarray) and moon == "Blue":
        pytest.xfail(reason="...")

I would like to be able to make this xfail "strict". AFAIK the only way to do this would be to explicitly write out all the parameter combinations and xfail the appropriate one:

@pytest.mark.parametrize('box, other, moon', [
    (pd.Index, 3.14, "Full"),
    ...
    pytest.param(pd.DataFrame, np.array([3.14]), "Blue", marks=pytest.mark.xfail(reason="...", strict=True, raises=ValueError)),
    ...
]
def test_thing(self, box, other, moon):
)

But that would get really verbose and defeat the point of a really nice pytest feature.

Would it be feasible to make pytest.xfail(reason="...", strict=True, raises=ValueError) not immediately raise, but instead continue the test and behave as if it had been xfailed from outside? (Is the idea clear?)

@asottile
Copy link
Member

a bit of a long shot, but you might find the helper I wrote here useful

@RonnyPfannschmidt RonnyPfannschmidt added the type: question general question, might be closed after 2 weeks of inactivity label Oct 23, 2018
@jbrockmendel
Copy link
Author

Thanks for taking a look. Sounds like a pipe dream for the time being. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question general question, might be closed after 2 weeks of inactivity
Projects
None yet
Development

No branches or pull requests

3 participants