pytest-dev / pytest-dev/pytest-factoryboy

Exposing a fixture for deferred factory evaluation

Open
#223 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
400
Forks
44
Avg merge
6h 34m
Merged PRs (30d)
1

Description

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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the pytest fixture integration and the existing factory fixture behavior, then use the book_factory example and its pytest.mark.parametrize case as the expected entry point. The work is done when a factory can be invoked inside the test body and supports deferred creation for decorator and transactional django.db.transaction.atomic() use cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.