Skip to content

Commit 8a3eed9

Browse files
committed
Add description of shared_db_wrapper to the docs
1 parent 4aa6035 commit 8a3eed9

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

docs/helpers.rst

+20
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,26 @@ transaction support. This is only required for fixtures which need
191191
database 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

0 commit comments

Comments
 (0)