diff options
author | Raphaël Barrois <raphael.barrois@polytechnique.org> | 2012-03-17 02:29:24 +0100 |
---|---|---|
committer | Raphaël Barrois <raphael.barrois@polytechnique.org> | 2012-03-17 02:29:24 +0100 |
commit | db643d44c51659d9460aa73eb21e7888b22896de (patch) | |
tree | ec38350de8e827cc0ff418f7946f3b399ab29e80 /factory/base.py | |
parent | 84019217057d1752fba021b2bfe940af5636977d (diff) | |
download | factory-boy-db643d44c51659d9460aa73eb21e7888b22896de.tar factory-boy-db643d44c51659d9460aa73eb21e7888b22896de.tar.gz |
Add a '@use_strategy' decorator for forcing alternate strategies.
Signed-off-by: Raphaël Barrois <raphael.barrois@polytechnique.org>
Diffstat (limited to 'factory/base.py')
-rw-r--r-- | factory/base.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/factory/base.py b/factory/base.py index 62131fb..ef782c7 100644 --- a/factory/base.py +++ b/factory/base.py @@ -614,3 +614,14 @@ def simple_generate(klass, create, **kwargs): def simple_generate_batch(klass, create, size, **kwargs): """Create a factory for the given class, and simple_generate instances.""" return make_factory(klass, **kwargs).simple_generate_batch(create, size) + + +def use_strategy(new_strategy): + """Force the use of a different strategy. + + This is an alternative to setting default_strategy in the class definition. + """ + def wrapped_class(klass): + klass.default_strategy = new_strategy + return klass + return wrapped_class |