Skip to content

Commit b3a8a9e

Browse files
Explain that the db fixture returns None
I was thinking that I could use the `db` fixture to access a database connection object within a test. However, the `db` fixture returns None. This documentation update makes it clear that the `db` fixture does not return an object, and explains that users should use from `django.db import connection` instead. Reference: See [this comment](#338 (comment)) on issue #338.
1 parent 203a7d6 commit b3a8a9e

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

docs/helpers.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,10 @@ is configured to be in the containing Django project.
231231
This fixture will ensure the Django database is set up. Only
232232
required for fixtures that want to use the database themselves. A
233233
test function should normally use the ``pytest.mark.django_db``
234-
mark to signal it needs the database.
234+
mark to signal it needs the database. This fixture does
235+
not return a database connection object. When you need a Django
236+
database connection or cursor, import it from Django using
237+
``from django.db import connection``.
235238

236239
``transactional_db``
237240
~~~~~~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)