summaryrefslogtreecommitdiff
path: root/factory/base.py
diff options
context:
space:
mode:
authorRaphaël Barrois <raphael.barrois@polytechnique.org>2012-08-17 01:22:47 +0200
committerRaphaël Barrois <raphael.barrois@polytechnique.org>2012-08-17 01:22:47 +0200
commit2611973bb62d38ff23471fdc115cdd09e351be50 (patch)
tree113cf3c40090b02d10f210ad20224cc40492f3dd /factory/base.py
parent20515351bb0db936873db5dae133ea317050079d (diff)
downloadfactory-boy-2611973bb62d38ff23471fdc115cdd09e351be50.tar
factory-boy-2611973bb62d38ff23471fdc115cdd09e351be50.tar.gz
Add support for passing non-kwarg parameters to factories.
Signed-off-by: Raphaël Barrois <raphael.barrois@polytechnique.org>
Diffstat (limited to 'factory/base.py')
-rw-r--r--factory/base.py16
1 files changed, 11 insertions, 5 deletions
diff --git a/factory/base.py b/factory/base.py
index 93aacde..a3d91b0 100644
--- a/factory/base.py
+++ b/factory/base.py
@@ -266,6 +266,9 @@ class BaseFactory(object):
# class.
_base_factory = None
+ # List of arguments that should be passed as *args instead of **kwargs
+ FACTORY_ARG_PARAMETERS = ()
+
@classmethod
def _setup_next_sequence(cls):
"""Set up an initial sequence value for Sequence attributes.
@@ -334,7 +337,6 @@ class BaseFactory(object):
args (tuple): arguments to use when building the class
kwargs (dict): keyword arguments to use when building the class
"""
-
return target_class(*args, **kwargs)
@classmethod
@@ -578,18 +580,22 @@ class Factory(BaseFactory):
**kwargs: arguments to pass to the creation function
"""
target_class = getattr(cls, CLASS_ATTRIBUTE_ASSOCIATED_CLASS)
+
+ # Extract *args from **kwargs
+ args = tuple(kwargs.pop(key) for key in cls.FACTORY_ARG_PARAMETERS)
+
if create:
# Backwards compatibility
creation_function = cls.get_creation_function()
if creation_function:
- return creation_function(target_class, **kwargs)
- return cls._create(target_class, **kwargs)
+ return creation_function(target_class, *args, **kwargs)
+ return cls._create(target_class, *args, **kwargs)
else:
# Backwards compatibility
building_function = cls.get_building_function()
if building_function:
- return building_function(target_class, **kwargs)
- return cls._build(target_class, **kwargs)
+ return building_function(target_class, *args, **kwargs)
+ return cls._build(target_class, *args, **kwargs)
@classmethod
def _generate(cls, create, attrs):