summaryrefslogtreecommitdiff
path: root/factory
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
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')
-rw-r--r--factory/base.py16
-rw-r--r--factory/containers.py2
2 files changed, 12 insertions, 6 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):
diff --git a/factory/containers.py b/factory/containers.py
index 6834f60..d50cb71 100644
--- a/factory/containers.py
+++ b/factory/containers.py
@@ -124,7 +124,7 @@ class DeclarationDict(dict):
return False
elif isinstance(value, declarations.OrderedDeclaration):
return True
- return (not name.startswith("_"))
+ return (not name.startswith("_") and not name.startswith("FACTORY_"))
def update_with_public(self, d):
"""Updates the DeclarationDict from a class definition dict.