diff options
Diffstat (limited to 'factory/declarations.py')
-rw-r--r-- | factory/declarations.py | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/factory/declarations.py b/factory/declarations.py index f068c0d..552ddf2 100644 --- a/factory/declarations.py +++ b/factory/declarations.py @@ -163,17 +163,20 @@ class Iterator(OrderedDeclaration): self.getter = getter if cycle: - self.iterator = itertools.cycle(iterator) - else: - self.iterator = iter(iterator) + iterator = itertools.cycle(iterator) + self.iterator = utils.ResetableIterator(iterator) def evaluate(self, sequence, obj, create, extra=None, containers=()): logger.debug("Iterator: Fetching next value from %r", self.iterator) - value = next(self.iterator) + value = next(iter(self.iterator)) if self.getter is None: return value return self.getter(value) + def reset(self): + """Reset the internal iterator.""" + self.iterator.reset() + class Sequence(OrderedDeclaration): """Specific OrderedDeclaration to use for 'sequenced' fields. |