File tree 1 file changed +20
-0
lines changed
1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -191,6 +191,26 @@ transaction support. This is only required for fixtures which need
191
191
database access themselves. A test function would normally use the
192
192
:py:func: `~pytest.mark.django_db ` mark to signal it needs the database.
193
193
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
+
194
214
``live_server ``
195
215
~~~~~~~~~~~~~~~
196
216
You can’t perform that action at this time.
0 commit comments