'Random model values inside list subfactory elements

I cannot find an answer to my question. The thing is that I want to generate an User factory model where inside will be a subfactory List with Addresses. Each Addresses element must have different/random values (I mean that each element has non-repeatable unique values).

In my current implementation, all of the elements have the same values (maybe seeding is necessary?)

Actual code:

from pydantic import BaseModel
from factory import Factory, List, Subfactory


class Address(BaseModel):
    Name: str


class User(BaseModel):
    Addresses: list[Address]


class AddressFactory(Factory):
    Name = fake.name()

    class Meta:
        model = Address


class UserFactory(Factory):
    Addresses = List([SubFactory(AddressFactory) for _ in range(3)])

    class Meta:
        model = User

Actual output:

> UserFactory()
> User(Addresses=[Address(Name='Isa Merkx'), Address(Name='Isa Merkx'), Address(Name='Isa Merkx')])

Desired Output:

> UserFactory()
> User(Addresses=[Address(Name='Isa Merkx'), Address(Name='John Smith'), Address(Name='Elon Musk')])


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source