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

Fix pytest.parametrize when argnames are specified as kwarg #2819

Merged
merged 4 commits into from
Oct 9, 2017

Conversation

leezu
Copy link
Contributor

@leezu leezu commented Oct 8, 2017

Previously only this worked:
@pytest.mark.parametrize("A", argvalues=[(A1, ), (A2, )])
Now argnames can be specified explicitly:
@pytest.mark.parametrize(argnames="A", argvalues=[(A1, ), (A2, )])

Copy link
Member

@RonnyPfannschmidt RonnyPfannschmidt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please also include a test for the behaviour

# skip directly parametrized arguments
argnames = func_params[0]
if "argnames" in parametrize_func.kwargs:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line directly breaks testing pytest in various cases, see the broken ci results

the defensive coding in the surrounding lines may look ludicrous, but python doesn't have monadic handling of defensive coding so we have to bite the bullet or include null types

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.007%) to 92.224% when pulling e89abe6 on leezu:fix_kwargs_fixtures into 761d552 on pytest-dev:master.

leezu added a commit to leezu/pytest that referenced this pull request Oct 8, 2017
@leezu
Copy link
Contributor Author

leezu commented Oct 8, 2017

Thanks @RonnyPfannschmidt . Please have a look at the updated version. I also added a test case. Turns out the bug is only triggered when parameterizing a test that relies on a parameterized fixture..

        import pytest

        @pytest.fixture(params=[1,2])
        def a(request):
            return request.param

        @pytest.mark.parametrize(argnames='b', argvalues=[1, 2])
        def test_func(a, b):
            pass

@coveralls
Copy link

Coverage Status

Coverage increased (+0.003%) to 92.235% when pulling e86ba41 on leezu:fix_kwargs_fixtures into 761d552 on pytest-dev:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.003%) to 92.235% when pulling e86ba41 on leezu:fix_kwargs_fixtures into 761d552 on pytest-dev:master.

@RonnyPfannschmidt RonnyPfannschmidt merged commit 46e3043 into pytest-dev:master Oct 9, 2017
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

Successfully merging this pull request may close these issues.

None yet

3 participants