-
Notifications
You must be signed in to change notification settings - Fork 41
Description
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
- Give up the assumption that the DB is clean/in some known state at the start of each test OR
- add the
dbfixture into any other fixture/test that relies on a factory fixture generated bypytest-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