Is it possible to parametrize on the values of a fixture? How/Why not? #11359
Answered
by
RonnyPfannschmidt
kunaltyagi
asked this question in
Q&A
-
I have a fixture, which returns a configuration dict. I want to parametrize my test on the values of a particular key. Eg: @pytest.fixture(scope="session")
def config():
return {"greet": ["Hola", "Hello", "Hi"], # just a sample, actually generated from config files
"count": [1,2,3,4,5,6,7,8,9],
"cities": ["SF", "NY"],
}
#####
@pytest.mark.parametrize("greet", HOW_TO_GET_THE_LIST_HERE)
def test_single_greeting(greet): # want just the greetings here, one by one, no count/cities
# checks if the greetings fit some criteria I can perform a loop inside a normal test, but this approach as a few drawbacks such as:
What doesn't work:
Ideal usage: something similar to the following: @pytest.mark.parametrize("greeting": config()["greet"])
def test_single_greeting(greeting):
pass def test_single_greeting(config, subtests):
for greeting in config["greet"]:
with subtests.test(msg=f"test_with_{greeting}")
pass |
Beta Was this translation helpful? Give feedback.
Answered by
RonnyPfannschmidt
Aug 28, 2023
Replies: 1 comment 3 replies
-
parameterization currently happens before fixtures get executed currently i believe some major internal changes are needed to enable that |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The subtests plugin provides that feature