import factory

from django.contrib.auth import get_user_model


class UserFactory(factory.django.DjangoModelFactory):
    username = factory.Faker("user_name")
    email = factory.Faker("email")
    first_name = factory.Faker("first_name")
    last_name = factory.Faker("last_name")

    class Meta:
        model = get_user_model()

import factory

from django.contrib.auth import get_user_model


class UserFactory(factory.django.DjangoModelFactory):
    username = factory.Faker("user_name")
    email = factory.Faker("email")
    first_name = factory.Faker("first_name")
    last_name = factory.Faker("last_name")

    class Meta:
        model = get_user_model()
        django_get_or_create = ('username',)

Fix race condition involving account usernames.
Fix race condition involving account usernames.

Fix race condition causing random test failures by using get_or_create
on generated usernames. See https://factoryboy.readthedocs.io/en/latest/orms.html#factory.django.DjangoOptions.django_get_or_create

  import factory
  
  from django.contrib.auth import get_user_model
  
  
  class UserFactory(factory.django.DjangoModelFactory):
      username = factory.Faker("user_name")
      email = factory.Faker("email")
      first_name = factory.Faker("first_name")
      last_name = factory.Faker("last_name")
  
      class Meta:
          model = get_user_model()
+         django_get_or_create = ('username',)
  
Fix race condition involving account usernames.
## Code Before:
import factory

from django.contrib.auth import get_user_model


class UserFactory(factory.django.DjangoModelFactory):
    username = factory.Faker("user_name")
    email = factory.Faker("email")
    first_name = factory.Faker("first_name")
    last_name = factory.Faker("last_name")

    class Meta:
        model = get_user_model()

## Instruction:
Fix race condition involving account usernames.
## Code After:
import factory

from django.contrib.auth import get_user_model


class UserFactory(factory.django.DjangoModelFactory):
    username = factory.Faker("user_name")
    email = factory.Faker("email")
    first_name = factory.Faker("first_name")
    last_name = factory.Faker("last_name")

    class Meta:
        model = get_user_model()
        django_get_or_create = ('username',)
