Recall & Review
beginner
What does the
ids parameter do in pytest.mark.parametrize?The
ids parameter provides custom names for each set of parameters. These names appear in test reports and help identify tests clearly.Click to reveal answer
beginner
How do you use
ids with a list of strings in pytest.mark.parametrize?You pass a list of strings to
ids, each string naming the corresponding parameter set. For example: @pytest.mark.parametrize('x,y', [(1,2), (3,4)], ids=['first', 'second']).Click to reveal answer
beginner
Why is using
ids helpful when running many parameterized tests?Using
ids makes test reports easier to read. Instead of seeing generic indexes, you see meaningful names that explain what each test case is about.Click to reveal answer
intermediate
Can
ids be a function in pytest.mark.parametrize? What does it do?Yes,
ids can be a function that takes a parameter set and returns a string. This lets you create dynamic, descriptive names for each test case.Click to reveal answer
intermediate
Show a simple example of
pytest.mark.parametrize using ids as a function.Example:<br>
@pytest.mark.parametrize('num', [1, 2, 3], ids=lambda x: f"num_{x}")
def test_example(num):
assert num > 0<br>This names tests as num_1, num_2, num_3.Click to reveal answer
What is the main purpose of the
ids parameter in pytest.mark.parametrize?✗ Incorrect
The
ids parameter lets you name each parameter set for clearer test reports.Which of these is a valid way to use
ids in pytest.mark.parametrize?✗ Incorrect
You must provide a list of strings or a function to
ids, not numbers or booleans.If you want dynamic test names based on parameter values, what should
ids be?✗ Incorrect
ids can be a function that takes a parameter and returns a descriptive string.What happens if you do not provide
ids in pytest.mark.parametrize?✗ Incorrect
Without
ids, pytest uses default numeric indexes to name parameter sets.Which of the following is NOT a benefit of using
ids in parameterized tests?✗ Incorrect
ids helps with naming and reporting but does not fix bugs automatically.Explain how to use the
ids parameter in pytest.mark.parametrize and why it is useful.Think about how test names appear in reports.
You got /4 concepts.
Describe a scenario where using a function for
ids in parameterized tests is better than using a list of strings.Consider large or changing test data.
You got /4 concepts.