diff options
Diffstat (limited to 'factory')
-rw-r--r-- | factory/base.py | 8 | ||||
-rw-r--r-- | factory/test_base.py | 17 |
2 files changed, 24 insertions, 1 deletions
diff --git a/factory/base.py b/factory/base.py index ff77e77..736a0e6 100644 --- a/factory/base.py +++ b/factory/base.py @@ -144,10 +144,16 @@ class BaseFactory(object): def __new__(cls, *args, **kwargs): raise RuntimeError('You cannot instantiate BaseFactory') - _next_sequence = 0 + _next_sequence = None + + @classmethod + def _setup_next_sequence(cls): + return 0 @classmethod def _generate_next_sequence(cls): + if cls._next_sequence is None: + cls._next_sequence = cls._setup_next_sequence() next_sequence = cls._next_sequence cls._next_sequence += 1 return next_sequence diff --git a/factory/test_base.py b/factory/test_base.py index b324680..2b8cb14 100644 --- a/factory/test_base.py +++ b/factory/test_base.py @@ -74,6 +74,23 @@ class FactoryTestCase(unittest.TestCase): self.assertEqual(test_object1.one, 'one1') self.assertEqual(test_object1.two, 'two1') + def testSequenceCustomBegin(self): + class TestObjectFactory(Factory): + @classmethod + def _setup_next_sequence(cls): + return 42 + + one = declarations.Sequence(lambda n: 'one' + n) + two = declarations.Sequence(lambda n: 'two' + n) + + test_object0 = TestObjectFactory.build() + self.assertEqual('one42', test_object0.one) + self.assertEqual('two42', test_object0.two) + + test_object1 = TestObjectFactory.build() + self.assertEqual('one43', test_object1.one) + self.assertEqual('two43', test_object1.two) + def testLazyAttribute(self): class TestObjectFactory(Factory): one = declarations.LazyAttribute(lambda a: 'abc' ) |