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

Support xfail inside parameterized.expand #117

Open
dzenilee opened this issue Feb 22, 2021 · 2 comments
Open

Support xfail inside parameterized.expand #117

dzenilee opened this issue Feb 22, 2021 · 2 comments

Comments

@dzenilee
Copy link

dzenilee commented Feb 22, 2021

What's the proper way to indicate that a test will fail (e.g., pytest's "xfail") with parameterized.expand?

I've tried using pytest.mark with parameterized.expand:

import unittest
import pytest
from parameterized import parameterized

class ModelRegressionTestCase(unittest.TestCase):
    def setUp(self):
        self.model = load_model()

    @parameterized.expand(
        [
            ("Word", "Word"),
            pytest.param("Word Second", "Word second",
                         marks=pytest.mark.xfail(reason="The reason it fails")),
        ]
    )
    def test_sanity(self, x, y):
        expectation = {"answer": y, "score": 1}
        result = self.model.predict(x)
        self.assertEqual(expectation, result)

But perhaps those are incompatible. I get a TypeError:

=================================== FAILURES ===================================
____________________ ModelRegressionTestCase.test_sanity_2 _____________________

a = (<test.test_model.ModelRegressionTestCase testMethod=test_sanity_2>,)

    @wraps(func)
    def standalone_func(*a):
>       return func(*(a + p.args), **p.kwargs)
E       TypeError: test_sanity() takes 3 positional arguments but 4 were given

../.local/lib/python3.6/site-packages/parameterized/parameterized.py:533: TypeError

Does parameterized support something like xfail specifically in the context of the expand decorator?

@souliane
Copy link

I think there's currently no way to expect an exception as beautifully as pytest.mark.xfail would allow to do.

Also, you are using pytest.param in your example, but parameterized has its own param class - it doesn't use pytest's one.

I would be very happy to see a xfail implementation in parameterized :-)

@gurashish1singh
Copy link

Bumping this! xfail in parameterized would be a very helpful addition!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants