Skip to content

Commit

Permalink
Force generation to use strategy defined within the factories meta
Browse files Browse the repository at this point in the history
- Default in case non-set is CREATE_STRATEGY. So this conforms to the absolute hardcoded default from before.
  • Loading branch information
Exelscior committed Oct 9, 2019
1 parent a873a8f commit f0fadcf
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pytest_factoryboy/fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ class Factory(factory_class):
if argname in request._fixturedef.argnames:
kwargs[key] = evaluate(request, request.getfixturevalue(argname))

strategy = factory.enums.CREATE_STRATEGY
strategy = Factory._meta.strategy
builder = factory.builder.StepBuilder(Factory._meta, kwargs, strategy)
step = factory.builder.BuildStep(builder=builder, sequence=Factory._meta.next_sequence())

Expand Down
4 changes: 3 additions & 1 deletion pytest_factoryboy/plugin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""pytest-factoryboy plugin."""

from collections import defaultdict
from factory import enums
import pytest


Expand Down Expand Up @@ -72,7 +73,8 @@ def after_postgeneration(self, request):
results = self.results.pop(model)
obj = request.getfixturevalue(model)
factory = self.model_factories[model]
factory._after_postgeneration(obj, create=True, results=results)
create = factory._meta.strategy == enums.CREATE_STRATEGY
factory._after_postgeneration(obj, create=create, results=results)

def evaluate(self, request):
"""Finalize, run deferred post-generation actions, etc."""
Expand Down

0 comments on commit f0fadcf

Please sign in to comment.