Recall & Review
beginner
What does using multiple parameters in pytest's @pytest.mark.parametrize decorator allow you to do?
It allows you to run the same test function with different sets of input values for multiple arguments, making tests more efficient and organized.
Click to reveal answer
beginner
How do you define multiple parameters in @pytest.mark.parametrize?
You list the parameter names as a comma-separated string, and provide a list of tuples where each tuple contains values for all parameters.
Click to reveal answer
beginner
Example: What will happen when this test runs?
@pytest.mark.parametrize('x,y', [(1,2), (3,4)])
def test_sum(x, y):
assert x + y > 0
The test will run twice: once with x=1 and y=2, and once with x=3 and y=4. Both should pass since sums are positive.
Click to reveal answer
beginner
Why is using multiple parameters in tests helpful in real life?
It saves time by testing many input combinations automatically, like checking different flavors of a recipe without cooking each separately.
Click to reveal answer
intermediate
What is a common mistake to avoid when using multiple parameters in pytest?
Make sure the number of values in each tuple matches the number of parameters declared, or pytest will raise an error.
Click to reveal answer
What does @pytest.mark.parametrize do with multiple parameters?
✗ Incorrect
The decorator runs the test repeatedly, each time with a different set of parameter values.
How do you specify multiple parameters in @pytest.mark.parametrize?
✗ Incorrect
You list parameter names as a string and provide a list of tuples with corresponding values.
What happens if the number of values in a tuple does not match the number of parameters?
✗ Incorrect
Mismatch causes pytest to raise a ValueError and stop execution.
Why is using multiple parameters in tests like trying different flavors of a recipe?
✗ Incorrect
It saves time by testing many inputs without writing separate tests.
Which of these is a valid way to parametrize two parameters x and y?
✗ Incorrect
Option A correctly lists parameters as a string and values as tuples.
Explain how to use multiple parameters in pytest's parametrize decorator with an example.
Think about how to run the same test with different inputs.
You got /3 concepts.
What are the benefits and common pitfalls of using multiple parameters in pytest tests?
Consider why this feature is useful and what errors to watch for.
You got /3 concepts.