Skip to content

Commit 93a96f6

Browse files
committed
docs: some minor fixes/improvements
1 parent 76170a8 commit 93a96f6

File tree

1 file changed

+36
-20
lines changed

1 file changed

+36
-20
lines changed

docs/helpers.rst

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ Markers
3232
of the test. This behavior is the same as Django's standard
3333
:class:`~django.test.TestCase` class.
3434

35-
In order for a test to have access to the database it must either
36-
be marked using the ``django_db`` mark or request one of the ``db``,
37-
``transactional_db`` or ``django_db_reset_sequences`` fixtures. Otherwise the
38-
test will fail when trying to access the database.
35+
In order for a test to have access to the database it must either be marked
36+
using the :func:`~pytest.mark.django_db` mark or request one of the :fixture:`db`,
37+
:fixture:`transactional_db` or :fixture:`django_db_reset_sequences` fixtures.
38+
Otherwise the test will fail when trying to access the database.
3939

4040
:type transaction: bool
4141
:param transaction:
@@ -60,8 +60,9 @@ Markers
6060
or may not help even if the function requesting your fixture has this marker
6161
applied, depending on pytest's fixture execution order. To access the
6262
database in a fixture, it is recommended that the fixture explicitly request
63-
one of the ``db``, ``transactional_db`` or ``django_db_reset_sequences``
64-
fixtures. See below for a description of them.
63+
one of the :fixture:`db`, :fixture:`transactional_db` or
64+
:fixture:`django_db_reset_sequences` fixtures. See below for a description of
65+
them.
6566

6667
.. note:: Automatic usage with ``django.test.TestCase``.
6768

@@ -115,6 +116,7 @@ pytest-django provides some pytest fixtures to provide dependencies for tests.
115116
More information on fixtures is available in the :ref:`pytest documentation
116117
<pytest:fixtures>`.
117118

119+
.. fixture:: rf
118120

119121
``rf`` - ``RequestFactory``
120122
~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -133,6 +135,8 @@ Example
133135
response = my_view(request)
134136
assert response.status_code == 200
135137

138+
.. fixture:: client
139+
136140
``client`` - ``django.test.Client``
137141
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
138142

@@ -164,6 +168,7 @@ To use `client` as an authenticated standard user, call its
164168
response = client.get('/private')
165169
assert response.content == 'Protected Area'
166170

171+
.. fixture:: admin_client
167172

168173
``admin_client`` - ``django.test.Client`` logged in as admin
169174
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -179,8 +184,8 @@ Example
179184
response = admin_client.get('/admin/')
180185
assert response.status_code == 200
181186

182-
Using the `admin_client` fixture will cause the test to automatically be marked for database use (no need to specify the
183-
``django_db`` mark).
187+
Using the `admin_client` fixture will cause the test to automatically be marked
188+
for database use (no need to specify the :func:`~pytest.mark.django_db` mark).
184189

185190
.. fixture:: admin_user
186191

@@ -190,9 +195,10 @@ Using the `admin_client` fixture will cause the test to automatically be marked
190195
An instance of a superuser, with username "admin" and password "password" (in
191196
case there is no "admin" user yet).
192197

193-
Using the `admin_user` fixture will cause the test to automatically be marked for database use (no need to specify the
194-
``django_db`` mark).
198+
Using the `admin_user` fixture will cause the test to automatically be marked
199+
for database use (no need to specify the :func:`~pytest.mark.django_db` mark).
195200

201+
.. fixture:: django_user_model
196202

197203
``django_user_model``
198204
~~~~~~~~~~~~~~~~~~~~~
@@ -210,6 +216,7 @@ Example
210216
def test_new_user(django_user_model):
211217
django_user_model.objects.create(username="someone", password="something")
212218

219+
.. fixture:: django_username_field
213220

214221
``django_username_field``
215222
~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -219,37 +226,43 @@ resolves to the user model's :attr:`~django.contrib.auth.models.CustomUser.USERN
219226
Use this fixture to make pluggable apps testable regardless what the username field
220227
is configured to be in the containing Django project.
221228

229+
.. fixture:: db
230+
222231
``db``
223232
~~~~~~~
224233

225-
.. fixture:: db
226-
227234
This fixture will ensure the Django database is set up. Only
228235
required for fixtures that want to use the database themselves. A
229-
test function should normally use the ``pytest.mark.django_db``
236+
test function should normally use the :func:`pytest.mark.django_db`
230237
mark to signal it needs the database. This fixture does
231238
not return a database connection object. When you need a Django
232239
database connection or cursor, import it from Django using
233240
``from django.db import connection``.
234241

242+
.. fixture:: transactional_db
243+
235244
``transactional_db``
236245
~~~~~~~~~~~~~~~~~~~~
237246

238247
This fixture can be used to request access to the database including
239248
transaction support. This is only required for fixtures which need
240249
database access themselves. A test function should normally use the
241-
``pytest.mark.django_db`` mark with ``transaction=True``.
250+
func:`pytest.mark.django_db` mark with ``transaction=True`` to signal
251+
it needs the database.
252+
253+
.. fixture:: django_db_reset_sequences
242254

243255
``django_db_reset_sequences``
244256
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
245257

246-
.. fixture:: django_db_reset_sequences
247-
248258
This fixture provides the same transactional database access as
249-
``transactional_db``, with additional support for reset of auto increment
250-
sequences (if your database supports it). This is only required for
251-
fixtures which need database access themselves. A test function should
252-
normally use the ``pytest.mark.django_db`` mark with ``transaction=True`` and ``reset_sequences=True``.
259+
:fixture:`transactional_db`, with additional support for reset of auto
260+
increment sequences (if your database supports it). This is only required for
261+
fixtures which need database access themselves. A test function should normally
262+
use the :func:`pytest.mark.django_db` mark with ``transaction=True`` and
263+
``reset_sequences=True``.
264+
265+
.. fixture:: live_server
253266

254267
``live_server``
255268
~~~~~~~~~~~~~~~
@@ -272,6 +285,8 @@ also directly concatenate a string to form a URL: ``live_server +
272285
In addition, using ``live_server`` will also trigger transactional
273286
database access, if not specified.
274287

288+
.. fixture:: settings
289+
275290
``settings``
276291
~~~~~~~~~~~~
277292

@@ -341,6 +356,7 @@ Example usage::
341356
Item.objects.create('foo')
342357
Item.objects.create('bar')
343358

359+
.. fixture:: mailoutbox
344360

345361
``mailoutbox``
346362
~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)