Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

258
Views
accesorio no encontrado usando Factoryboy SubFactory

Recibo un error al construir fábricas con subfábricas para probar modelos Django. Con modelos:

 class Space(ExportModelOperationsMixin('space'), models.Model): name = models.CharField(max_length=128, default='Default') class ShoppingListEntry(models.Model): food = models.ForeignKey(Food) space = models.ForeignKey(Space) class Food(models.Model): name = models.CharField(max_length=128) description = models.TextField(default='', blank=True) space = models.ForeignKey(Space)

y accesorios:

 class SpaceFactory(factory.django.DjangoModelFactory): name = factory.LazyAttribute(lambda x: faker.word()) class FoodFactory(factory.django.DjangoModelFactory): name = factory.LazyAttribute(lambda x: faker.sentence(nb_words=3)) description = factory.LazyAttribute(lambda x: faker.sentence(nb_words=10)) space = factory.SubFactory(SpaceFactory) class ShoppingListEntryFactory(factory.django.DjangoModelFactory): food = factory.SubFactory(FoodFactory, space=factory.SelfAttribute('..space')) space = factory.SubFactory(SpaceFactory)

y prueba

 register(SpaceFactory, 'space_1') register(ShoppingListEntryFactory, 'shopping_list_entry', space=LazyFixture('space_1')) def test_list_space(shopping_list_entry): assert 1 == 1

arroja el siguiente error

 Failed with Error: [undefined]failed on setup with def test_list_space(sle_1): file <string>, line 2: source code not available file <string>, line 2: source code not available E fixture 'food__name' not found

Estoy luchando por descubrir cómo solucionar este problema.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Reemplazar el registro de fábrica de register(ShoppingListEntryFactory, ...) con un accesorio pytest resolvió el problema.

 @pytest.fixture def shopping_list_entry(space_1): return ShoppingListEntryFactory.create(space=space_1)
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!