Why are the relatedFactory variable names in factory -boy affected when starting / creating factory instances?

When I named the relatedFactory variables pv_something, the factories will not start until the post_generation method is post_generation . When I renamed the variables to param_val_something , they will be run before the post_generation method.

In the following code, RelatedFactory does not start until post_generation , so self.something_set.all() empty, and the line t.something_else = 'abc' never executed.

 class ThingFactory(factory.DjangoModelFactory): class Meta: model = Thing name = 'a thing' pv_something = factory.RelatedFactory(SomethingFactory, 'thing') @factory.post_generation def post(self, create, extracted, **kwargs): for t in self.something_set.all(): t.something_else = 'abc' 

In the following code, the only difference is renaming the pv_something variable to param_val_something . Now self.something_set.all() not empty, and the line t.something_else = 'abc' is executed.

 class ThingFactory(factory.DjangoModelFactory): class Meta: model = Thing name = 'a thing' param_val_something = factory.RelatedFactory(SomethingFactory, 'thing') @factory.post_generation def post(self, create, extracted, **kwargs): for t in self.something_set.all(): t.something_else = 'abc' 

I am using Python 3.4.3, Django 1.8.5 and factory -boy 2.5.2.

Midnight Friday night, it almost sent me over the edge.

+3
source share

All Articles