Bird
0
0

Identify the error in this PyTest test code:

medium📝 Debug Q6 of 15
PyTest - Writing Assertions
Identify the error in this PyTest test code:
def test_example():
    x = 5
    assert x = 5
ATest fails because x is not 5
BTest passes successfully
CSyntaxError due to assignment in assert
DRuntimeError due to missing return
Step-by-Step Solution
Solution:
  1. Step 1: Check assert syntax

    Using '=' in assert is invalid; it should be '==' for comparison.
  2. Step 2: Identify error type

    Python raises SyntaxError for assignment inside assert condition.
  3. Final Answer:

    SyntaxError due to assignment in assert -> Option C
  4. Quick Check:

    Assignment in assert causes syntax error [OK]
Quick Trick: Use '==' in assert, '=' causes syntax error [OK]
Common Mistakes:
MISTAKES
  • Using '=' instead of '==' in assert
  • Assuming test fails instead of syntax error
  • Expecting runtime error instead of syntax error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PyTest Quizzes