summaryrefslogtreecommitdiff
path: root/factory
diff options
context:
space:
mode:
Diffstat (limited to 'factory')
-rw-r--r--factory/fuzzy.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/factory/fuzzy.py b/factory/fuzzy.py
index 564264e..4e6a03d 100644
--- a/factory/fuzzy.py
+++ b/factory/fuzzy.py
@@ -113,13 +113,21 @@ class FuzzyText(BaseFuzzyAttribute):
class FuzzyChoice(BaseFuzzyAttribute):
- """Handles fuzzy choice of an attribute."""
+ """Handles fuzzy choice of an attribute.
+
+ Args:
+ choices (iterable): An iterable yielding options; will only be unrolled
+ on the first call.
+ """
def __init__(self, choices, **kwargs):
- self.choices = list(choices)
+ self.choices = None
+ self.choices_generator = choices
super(FuzzyChoice, self).__init__(**kwargs)
def fuzz(self):
+ if self.choices is None:
+ self.choices = list(self.choices_generator)
return _random.choice(self.choices)