Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Factory Boy] Create factory without model #20

Open
kenvontucky opened this issue Dec 16, 2022 · 0 comments
Open

[Factory Boy] Create factory without model #20

kenvontucky opened this issue Dec 16, 2022 · 0 comments

Comments

@kenvontucky
Copy link
Collaborator

Description

Factory Boy requires a model to define a factory, however sometimes there's a need of taking advantage of the factory boy functionality without a model.

Requirements

Add an entry under Factory boy, where a solution such as the one below is presented.

from typing import NamedTuple
import factory


class TestUser(NamedTuple):
    id: int
    name: str


class TestUserFactory(factory.Factory):
    class Meta:
        model = TestUser

    id = factory.Sequence(lambda n: 1000 + n)
    name = factory.Faker('name')

Acceptance Criteria

Provide a complete example

tuf = TestUserFactory()

and

tuf = TestUserFactory(name="John O'Reilly")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant