Bird
Raised Fist0

Find the bug in this Agile test status update code:

medium📝 Debug Q7 of Q15
Testing Fundamentals - Testing Models and Approaches
Find the bug in this Agile test status update code:
test_results = {'login': 'pass', 'search': 'fail'}
if test_results['checkout'] == 'pass':
    print('Checkout passed')
else:
    print('Checkout failed')
ASyntax error in if statement
BKeyError due to missing 'checkout' key
CIncorrect print statement syntax
DLogical error in else block
Step-by-Step Solution
Solution:
  1. Step 1: Check dictionary keys accessed

    The code tries to access 'checkout' key which does not exist in test_results.
  2. Step 2: Understand Python behavior on missing keys

    Accessing a missing key raises a KeyError exception.
  3. Final Answer:

    KeyError due to missing 'checkout' key -> Option B
  4. Quick Check:

    Missing dict key causes KeyError [OK]
Quick Trick: Access dict keys safely to avoid KeyError [OK]
Common Mistakes:
MISTAKES
  • Assuming missing keys return None
  • Ignoring exception possibility
  • Confusing syntax error with runtime error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Testing Fundamentals Quizzes