Repository navigation
How to create two arguments in "pytest_generate_tests(metafunc)" #10241
Unanswered
zhangmingyuu
asked this question in
Q&A
Replies: 2 comments
This comment was marked as low quality.
This comment was marked as low quality.
|
Yes. If the two values belong together, pass both parameter names to a single # test_example.py
def pytest_generate_tests(metafunc):
if {"test_scope", "second_scope"}.issubset(
metafunc.fixturenames
):
metafunc.parametrize(
"test_scope,second_scope",
[("first", 1), ("second", 2)],
)
def test_pair(test_scope, second_scope):
assert {"first": 1, "second": 2}[test_scope] == second_scopeThis produces two cases: For your existing variables, the parametrization would be: metafunc.parametrize(
"test_scope,second_scope",
[(scope, scope2)],
)Your original approach with two separate calls is also valid when both parameters are requested. With multiple values in each call, however, it generates every combination rather than matching values as pairs. Also, if the condition in your example is literal Python, use The paired example was verified with pytest 9.2.0: Reference: pytest parametrization documentation. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Hi, dear developers:
Can I specify two custom parameters in this method like below:
The problem I encountered first is: when I receive custom parameters, I need to create two different parameters at the same time,
I don't know if my problem is described clearly enough, if there is something unclear, please let me know
Thank you
All reactions