from django.contrib.auth.models import User
import factory


class UserFactory(factory.DjangoModelFactory):
    class Meta:
        model = User

    username = factory.Sequence('User {}'.format)

    @factory.post_generation
    def password(self, create, extracted, **kwargs):
        self.raw_password = extracted or 'default_password'
        self.set_password(self.raw_password)
        if create:
            self.save()

from django.contrib.auth.models import User
import factory


class UserFactory(factory.DjangoModelFactory):
    username = factory.Sequence('User {}'.format)

    class Meta:
        model = User

    @factory.post_generation
    def password(self, create, extracted, **kwargs):
        self.raw_password = 'default_password' if extracted is None else extracted
        self.set_password(self.raw_password)
        if create:
            self.save()

Update factory raw_password