Bird
0
0

Why does this test fail?

medium📝 Debug Q7 of 15
Django - Testing Django Applications
Why does this test fail?
form = ProfileForm(data={'age': 'twenty'})
assert form.is_valid()
AData dictionary keys are incorrect
BForm is missing required CSRF token
CAge field expects an integer, but got a string
Dassert is not valid in Django tests
Step-by-Step Solution
Solution:
  1. Step 1: Check field type and input value

    The age field expects an integer, but 'twenty' is a non-numeric string.
  2. Step 2: Understand validation failure

    Non-integer input causes form.is_valid() to return False, failing the assertion.
  3. Final Answer:

    Age field expects an integer, but got a string -> Option C
  4. Quick Check:

    Field type mismatch causes validation failure [OK]
Quick Trick: Match input types to form field types to pass validation [OK]
Common Mistakes:
MISTAKES
  • Blaming CSRF token in form tests
  • Assuming assert is invalid in tests
  • Ignoring type mismatch errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes