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

Exposing a fixture for deferred factory evaluation #223

Open
youtux opened this issue Sep 30, 2024 · 0 comments
Open

Exposing a fixture for deferred factory evaluation #223

youtux opened this issue Sep 30, 2024 · 0 comments

Comments

@youtux
Copy link
Contributor

youtux commented Sep 30, 2024

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