Bird
0
0

Given this code, what will be the test ID for the third test case?

medium📝 Predict Output Q5 of 15
PyTest - Parametrize
Given this code, what will be the test ID for the third test case?
@pytest.mark.parametrize('val', [5, 0, -1], ids=lambda x: f"val_{x}")
def test_val(val):
    assert val != 0
Atest_val[val_5]
Btest_val[val_0]
Ctest_val[val_1]
Dtest_val[val_-1]
Step-by-Step Solution
Solution:
  1. Step 1: Understand lambda IDs usage

    The ids parameter uses a lambda to create IDs like 'val_5', 'val_0', 'val_-1'.
  2. Step 2: Identify third test case ID

    The third value is -1, so ID is 'val_-1', making the test ID test_val[val_-1].
  3. Final Answer:

    test_val[val_-1] -> Option D
  4. Quick Check:

    Lambda IDs create 'val_' + value strings [OK]
Quick Trick: Lambda IDs format test names dynamically [OK]
Common Mistakes:
MISTAKES
  • Confusing index with value
  • Ignoring negative sign in ID
  • Assuming default numeric IDs

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes