pytest-dev / pytest-dev/pytest
Improve ParameterSet with nested ParameterSet objects
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 14.5k
- Forks
- 3.4k
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 35
Description
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" - https://github.com/vgorkavenko/pytest/commit/99c0712c5ec40773369ce1d6fc4cf60724544136
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing pytest.mark.parametrize and ParameterSet handling, then review the referenced napkin solution commit. Done means nested ParameterSet values are unpacked, nested and parent ids are combined with parent ids taking precedence, and marks from all levels are merged without changing simple-value behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100