I am using factory_boy
to build some fixtures in Django.
I want to use factory.LazyAttribute
to build one attribute based on the condition of another attribute.
class MyFactory(factory.django.DjangoModelFactory):
class Meta:
model = MyModel
title = 'My Title' if random() < 0.5 else None
description = factory.LazyAttribute(
lambda a: factory.Faker(
'paragraph', nb_sentences=1, variable_nb_sentences=False
) if a.title else None)
However, this returns a string
being <factory.faker.Faker object at 0x000001B10597BB20>
rather than executing the correct paragraph generation.
Where am I going wrong?
factory.fuzzy.FuzzyChoice
is depreciated, how would you implement this withFaker
so that it is called on each object? – Vanesavanessa