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

pytest_fixture_plus does not honor parameter id #30

Closed
Sup3rGeo opened this issue Mar 22, 2019 · 4 comments
Closed

pytest_fixture_plus does not honor parameter id #30

Sup3rGeo opened this issue Mar 22, 2019 · 4 comments

Comments

@Sup3rGeo
Copy link

Hi, another one! :)

Example:

from pytest_cases import pytest_fixture_plus as fixture
import pytest

@pytest.fixture(params=[
    pytest.param(1, id="p_a"),
    pytest.param(2, id="p_b"),
])
def pyfix(request):
    return request.param

@fixture
@pytest.mark.parametrize("arg1, arg2", [
    pytest.param(1,2, id="f_a"),
    pytest.param(3,4, id="f_b")
])
def myfix(arg1, arg2):
    return arg1, arg2

@pytest.mark.parametrize("arg3, arg4", [
    pytest.param(10,20, id="t_a"),
    pytest.param(30,40, id="t_b")
])
def test_one(pyfix, myfix, arg3, arg4):
    print(myfix)

result:

test_one.py::test_one[p_a-1-2-t_a] PASSED                                                                                                                                                                                                                [ 12%]
test_one.py::test_one[p_a-1-2-t_b] PASSED                                                                                                                                                                                                                [ 25%]
test_one.py::test_one[p_a-3-4-t_a] PASSED                                                                                                                                                                                                                [ 37%]
test_one.py::test_one[p_a-3-4-t_b] PASSED                                                                                                                                                                                                                [ 50%]
test_one.py::test_one[p_b-1-2-t_a] PASSED                                                                                                                                                                                                                [ 62%]
test_one.py::test_one[p_b-1-2-t_b] PASSED                                                                                                                                                                                                                [ 75%]
test_one.py::test_one[p_b-3-4-t_a] PASSED                                                                                                                                                                                                                [ 87%]
test_one.py::test_one[p_b-3-4-t_b] PASSED                                                                                                                                                                                                                [100%]

expected result:

test_one.py::test_one[p_a-f_a-t_a] PASSED                                                                                                                                                                                                                [ 12%]
test_one.py::test_one[p_a-f_a-t_b] PASSED                                                                                                                                                                                                                [ 25%]
test_one.py::test_one[p_a-f_b-t_a] PASSED                                                                                                                                                                                                                [ 37%]
test_one.py::test_one[p_a-f_b-t_b] PASSED                                                                                                                                                                                                                [ 50%]
test_one.py::test_one[p_b-f_a-t_a] PASSED                                                                                                                                                                                                                [ 62%]
test_one.py::test_one[p_b-f_a-t_b] PASSED                                                                                                                                                                                                                [ 75%]
test_one.py::test_one[p_b-f_b-t_a] PASSED                                                                                                                                                                                                                [ 87%]
test_one.py::test_one[p_b-f_b-t_b] PASSED                                                                                                                                                                                                                [100%]
@smarie
Copy link
Owner

smarie commented Mar 22, 2019

Noted. A workaround is to use ids= at the pytest.mark.parametrize level. I'll see what I can do then, it is probably again some small details, but as always since my plugin is compliant with pytest 2, 3, and 4 I have a couple checks to make.

@smarie smarie closed this as completed in 3495438 Mar 25, 2019
@smarie
Copy link
Owner

smarie commented Mar 25, 2019

Fixed in 1.4.2. Note that I also fixed that for marks too, you can test it by using a skip mark :

@pytest_fixture_plus
@pytest.mark.parametrize("arg1, arg2", [
    (1, 2),
    pytest.param(3, 4, id="my_custom_id"),
    pytest.param(5, 6, id="skipped", marks=pytest.mark.skip)
])
def myfix2(arg1, arg2):
    return arg1, arg2

@adnanmuttaleb
Copy link

what is pytest_param @smarie ?

@smarie
Copy link
Owner

smarie commented Jan 16, 2020

Oops it was pytest.param I guess. That's the usual way to customize a single parametrized test in pytest, see https://docs.pytest.org/en/latest/parametrize.html#pytest-mark-parametrize-parametrizing-test-functions

image

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