Bird
0
0

What will happen if you call UserFactory.create() but the factory has a required field email without a default value?

medium📝 component behavior Q5 of 15
Django - Testing Django Applications
What will happen if you call UserFactory.create() but the factory has a required field email without a default value?
ACreates user with email set to None
BAutomatically generates a random email
CRaises a validation error due to missing email
DCreates user but email is empty string
Step-by-Step Solution
Solution:
  1. Step 1: Understand required fields in Factory Boy

    If a required model field has no default and no factory value, creation fails validation.
  2. Step 2: Check behavior of missing required field

    Calling .create() tries to save to DB, raising validation error if required fields are missing.
  3. Final Answer:

    Raises a validation error due to missing email -> Option C
  4. Quick Check:

    Missing required field causes validation error [OK]
Quick Trick: Required fields must have factory defaults or cause errors [OK]
Common Mistakes:
MISTAKES
  • Assuming Factory Boy auto-generates missing required fields
  • Expecting None or empty string instead of error
  • Confusing .create() with .build() behavior

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes