Skip to content

Commit

Permalink
Add description of shared_db_wrapper to the docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ktosiek committed Oct 4, 2015
1 parent f40fddf commit 38cc40c
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions docs/helpers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,26 @@ transaction support. This is only required for fixtures which need
database access themselves. A test function would normally use the
:py:func:`~pytest.mark.django_db` mark to signal it needs the database.

``shared_db_wrapper``
~~~~~~~~~~~~~~~~~~~~~

This fixture can be used to create long-lived state in the database.
It's meant to be used from fixtures with scope bigger than ``function``.
It provides a context manager that will create a new database savepoint for you,
and will take care to revert it when your fixture gets cleaned up.

At the moment it does not work with ``transactional_db``,
as the fixture itself depends on transactions.
It also needs Django >= 1.6, as it's based on the ``atomic`` API.

Example usage::

@pytest.fixture(scope='module')
def some_users(request, shared_db_wrapper):
with shared_db_wrapper(request):
return [User.objects.create(username='no {}'.format(i))
for i in range(1000)]

``live_server``
~~~~~~~~~~~~~~~

Expand Down

0 comments on commit 38cc40c

Please sign in to comment.