Bird
0
0

Given this factory:

medium📝 component behavior Q4 of 15
Django - Testing Django Applications
Given this factory:
class BookFactory(factory.DjangoModelFactory):
    class Meta:
        model = Book
    title = "Sample Book"
    pages = 100

What will BookFactory().pages return?
ANone
B0
C100
DRaises an error
Step-by-Step Solution
Solution:
  1. Step 1: Understand attribute assignment in Factory Boy

    Attributes defined in the factory class are used as default values for created instances.
  2. Step 2: Check the value of pages in the factory

    The factory sets pages = 100, so the created instance will have pages equal to 100.
  3. Final Answer:

    100 -> Option C
  4. Quick Check:

    Factory attribute value = 100 [OK]
Quick Trick: Factory attributes become default field values [OK]
Common Mistakes:
MISTAKES
  • Expecting None if not set in model
  • Confusing factory attribute with model default
  • Thinking factory raises error without explicit call

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes