Skip to content

How to set report portal test case ids to be same ids passed in the parametrize marker #396

@abhagraw

Description

@abhagraw

Hello,

Pytest parameterize marker provides the option to pass ids for the parameterized test.

Referring to the following -

from datetime import datetime, timedelta

import pytest

testdata = [
    (datetime(2001, 12, 12), datetime(2001, 12, 11), timedelta(1)),
    (datetime(2001, 12, 11), datetime(2001, 12, 12), timedelta(-1)),
]
@pytest.mark.parametrize("a,b,expected", testdata, ids=["forward", "backward"])
def test_timedistance_v1(a, b, expected):
    diff = a - b
    assert diff == expected

Collected tests would be -

<Function test_timedistance_v1[forward]>
<Function test_timedistance_v1[backward]>

In report portal, the test name would as per the id passed, but the test case id would have the values of parameters instead of the ids passed.
so test name would be - test_timedistance_v1[forward], but
test case id would be test_timedistance_v1[datetime(2001, 12, 12), datetime(2001, 12, 11), timedelta(1)]

Is it possible to provide an option to set the test case ids in report portal using the ids passed to the parameterize marker?

Currently to achieve the same, I have to add the ids I want as another parameter to the test -

testdata = [
    (datetime(2001, 12, 12), datetime(2001, 12, 11), timedelta(1), "forward"),
    (datetime(2001, 12, 11), datetime(2001, 12, 12), timedelta(-1), "backward"),
]

@pytest.mark.parametrize("a,b,expected,rp_id", testdata, ids=["forward", "backward"])
@pytest.mark.tc_id(parameterized=True, params="rp_id")
def test_timedistance_v1(a, b, expected, rp_id):

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions