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

please also include a test for the behaviour

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

This comment has been minimized.

@RonnyPfannschmidt

RonnyPfannschmidt Oct 8, 2017
Member

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

@coveralls coveralls commented Oct 8, 2017

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 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

@leezu leezu force-pushed the leezu:fix_kwargs_fixtures branch from 43ef7d3 to e86ba41 Oct 8, 2017
@coveralls
Copy link

@coveralls coveralls commented Oct 8, 2017

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

@coveralls coveralls commented Oct 8, 2017

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
2 checks passed
2 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants