File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -191,6 +191,26 @@ transaction support. This is only required for fixtures which need
191191database access themselves. A test function would normally use the
192192:py:func: `~pytest.mark.django_db ` mark to signal it needs the database.
193193
194+ ``shared_db_wrapper ``
195+ ~~~~~~~~~~~~~~~~~~~~~
196+
197+ This fixture can be used to create long-lived state in the database.
198+ It's meant to be used from fixtures with scope bigger than ``function ``.
199+ It provides a context manager that will create a new database savepoint for you,
200+ and will take care to revert it when your fixture gets cleaned up.
201+
202+ At the moment it does not work with ``transactional_db ``,
203+ as the fixture itself depends on transactions.
204+ It also needs Django >= 1.6, as it's based on the ``atomic `` API.
205+
206+ Example usage::
207+
208+ @pytest.fixture(scope='module')
209+ def some_users(request, shared_db_wrapper):
210+ with shared_db_wrapper(request):
211+ return [User.objects.create(username='no {}'.format(i))
212+ for i in range(1000)]
213+
194214``live_server ``
195215~~~~~~~~~~~~~~~
196216
You can’t perform that action at this time.
0 commit comments