Skip to content

Exposing a fixture for deferred factory evaluation #223

Description

@youtux

It'd be nice to be able to expose a fixture (maybe the factory fixture?) that can be invoked in the test invocation.

Here's a few use cases:

  • creating the object when using a decorator, e.g. factory.django.mute_signals(signals.post_save)
  • create the object imperatively in the test body, for example if you use @pytest.mark.django_db(transactional=True), and you need to create your object within a django.db.transaction.atomic() context manager.
class Book:
    name: str

class BookFactory(Factory):
    name = "foo"


@pytest.mark.parametrize("book__name", ["bar"])
def test_book_initialise_later(book_factory):
    book = book_factory()
    assert book.name == bar

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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