Skip to content

Request other fixtures in fixtures generated by register #201

@sullivan-sean

Description

@sullivan-sean

I'd like support for including other fixtures as dependencies for the fixtures generated by pytest-factoryboy

I'm using https://github.com/pytest-dev/pytest-django. This library requires that tests/fixtures that operate on the DB request their db fixture to ensure DB operations can be put in transactions. If this fixture is not included for a DB operation, that operation cannot be rolled back after a test is complete and the result of the operation will persist in the DB across other tests.

register(UserFactory, request_fixtures=['db'])

which would output a user_factory() fixture that requests the db fixture from pytest-django.


Without this feature, the option to use these two libraries together are very limited. I could either

  1. Give up the assumption that the DB is clean/in some known state at the start of each test OR
  2. add the db fixture into any other fixture/test that relies on a factory fixture generated by pytest-factoryboy

My team heavily relies on the assumption of clean DB state so that, e.g. tests can be run in different orders, etc. So giving up 1 is not an acceptable solution. 2 is cumbersome and error prone: if a developer forgets to add the db fixture for a single test, it breaks the assumption from 1 and we again run into weird, unexpected issues where tests will fail if run in different orders, or if all/part of the test suite is run

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