Bird
0
0

What is wrong with this factory code?

medium📝 Debug Q14 of 15
Django - Testing Django Applications
What is wrong with this factory code?
class ProductFactory(factory.DjangoModelFactory):
    class Meta:
        model = Product
    name = factory.Faker('product_name')
    price = factory.Faker('float')
AFaker does not have a 'product_name' provider
BThe 'float' provider requires arguments to specify range
CMissing import of factory module
DMeta class should be outside the factory class
Step-by-Step Solution
Solution:
  1. Step 1: Check Faker providers used

    Faker has no built-in 'product_name' provider, but this is a common custom name; however, 'float' requires arguments like min and max.
  2. Step 2: Identify the error cause

    Using factory.Faker('float') without arguments causes an error because Faker's float provider needs parameters.
  3. Final Answer:

    The 'float' provider requires arguments to specify range -> Option B
  4. Quick Check:

    Faker float needs min/max args [OK]
Quick Trick: Faker float needs range arguments to work [OK]
Common Mistakes:
MISTAKES
  • Assuming 'product_name' is always valid
  • Ignoring required arguments for Faker float
  • Thinking Meta class placement is wrong

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes