diff options
author | Raphaël Barrois <raphael.barrois@polytechnique.org> | 2013-06-10 01:18:54 +0200 |
---|---|---|
committer | Raphaël Barrois <raphael.barrois@polytechnique.org> | 2013-06-10 01:18:54 +0200 |
commit | 85dde20cf2e337a4e0b7de47d067edfaf2e633ab (patch) | |
tree | a966d40b8dc24c65e8c84c282231a662eb55be46 /factory/base.py | |
parent | 639e5cd1c6baf1cb19d9134545e29fbb5ba16d99 (diff) | |
download | factory-boy-85dde20cf2e337a4e0b7de47d067edfaf2e633ab.tar factory-boy-85dde20cf2e337a4e0b7de47d067edfaf2e633ab.tar.gz |
Add Factory.reset_sequence.
Diffstat (limited to 'factory/base.py')
-rw-r--r-- | factory/base.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/factory/base.py b/factory/base.py index 23fdac7..ff5404f 100644 --- a/factory/base.py +++ b/factory/base.py @@ -240,6 +240,21 @@ class BaseFactory(object): FACTORY_HIDDEN_ARGS = () @classmethod + def reset_sequence(cls, value=None, force=False): + """Reset the sequence counter.""" + if cls._base_factory: + if force: + cls._base_factory.reset_sequence(value=value) + else: + raise ValueError( + "Cannot reset the sequence of a factory subclass. " + "Please call reset_sequence() on the root factory, " + "or call reset_sequence(forward=True)." + ) + else: + cls._next_sequence = value + + @classmethod def _setup_next_sequence(cls): """Set up an initial sequence value for Sequence attributes. |