Skip to content

[Factory Boy] Create factory without model #20

@kenvontucky

Description

@kenvontucky

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")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions