Improve ParameterSet with nested ParameterSet objects · Issue #9074 · pytest-dev/pytest (original) (raw)
What's the problem this feature will solve?
I want the possibility to combinate ParameterSet objects to parametrize tests
Describe the solution you'd like
I want nested ParameterSet objects to be unpacked and combined their ids and marks
For example, I have this test:
@pytest.mark.parametrize( "a,b,c", [ pytest.param( pytest.param(1, id="this_is_one"), pytest.param(2, id="this_is_two"), pytest.param(3, id="this_is_three"), ) ] ) def test_example(a, b, c): assert (1, 2, 3) == (a, b, c)
This test won’t pass now, because nested ParameterSet objects throw in the test "as-is".
FAILED test.py::test_example[a0-b0-c0] - AssertionError: assert (1, 2, 3) == (ParameterSet...)
This is logical behavior, but useless.
I suggest unpack nested ParameterSet objects and merge their ids and marks. If parent ParameterSet has an id - it rewrites nested ids.
The example above will in collect:<Function test_example[this_is_one-this_is_two-this_is_three]>
Here are a few more examples
1. ID rewriting
@pytest.mark.parametrize( "a,b,c", [ pytest.param( pytest.param(1, id="this_is_one"), pytest.param(2, id="this_is_two"), pytest.param(3, id="this_is_three"), id="one_two_three" ) ] )
<Function test_example[one_two_three]>
2. Use simple values with ParameterSet
@pytest.mark.parametrize( "a,b,c", [ pytest.param( 1, pytest.param(2, id="this_is_two"), 3, ) ] )
<Function test_example[1-this_is_two-3]>
3. Merge marks
@pytest.mark.parametrize( "a,b,c", [ pytest.param( pytest.param(1, id="this_is_one", marks=[pytest.mark.one]), pytest.param(2, id="this_is_two", marks=[pytest.mark.two]), pytest.param(3, id="this_is_three", marks=[pytest.mark.three]), id="one_two_three", marks=[pytest.mark.full] ) ] )
In this case, marks merged in one list - [one, two, three, full]
I have a solution that works, but I wrote it "on a napkin" - vgorkavenko@99c0712