I'm seeing duplicate values being generated when using randint and factory_boy. My test fails when checking for the asset for each object. The barcode is also the same between the two when calling create() on the factory.
Do I need to provide a different seed before each object creation?
Packages
- factory-boy 2.11.1
- Faker 1.0.4
- python 2.7
- django 1.11
Files
seed/factories.py
import factory
from A1.models import *
from random import randint, random
faker = Factory.create()
class AssetFactory(factory.DjangoModelFactory):
class Meta:
model = Asset
asset = "ABC" + str(randint(0000, 9999))
barcode = "AA" + randint(111111, 999999)
user = factory.lazy_attribute(lambda x: faker.name())
tests.py
def test_randomCreation(self):
new_asset = AssetFactory.create()
new_asset2 = AssetFactory.create()
self.assertNotEqual(new_asset.asset, new_asset2.asset) #FAILS
A1/models.py
class Asset(models.Model):
asset = models.CharField(max_length=255, verbose_name="Asset")
barcode = models.CharField(max_length=255)
user = models.CharField(max_length=255)
May someone point me in the right direction? Thanks in advance!!