@@ -506,17 +506,26 @@ def django_test_environment(request: pytest.FixtureRequest) -> Generator[None, N
506506
507507@pytest .fixture (scope = "session" )
508508def django_db_blocker (request : pytest .FixtureRequest ) -> DjangoDbBlocker | None :
509- """Wrapper around Django's database access.
509+ """Block or unblock database access.
510510
511- This object can be used to re-enable database access. This fixture is used
512- internally in pytest-django to build the other fixtures and can be used for
513- special database handling.
511+ This is an advanced feature for implementing database fixtures.
514512
515- The object is a context manager and provides the methods
516- .unblock()/.block() and .restore() to temporarily enable database access.
513+ By default, pytest-django blocks access the the database. In tests which
514+ request access to the database, the access is automatically unblocked .
517515
518- This is an advanced feature that is meant to be used to implement database
519- fixtures.
516+ In a test or fixture context where database access is blocked, you can
517+ temporarily unblock access as follows::
518+
519+ with django_db_blocker.unblock():
520+ ...
521+
522+ In a test or fixture context where database access is not blocked, you can
523+ temporarily block access as follows::
524+
525+ with django_db_blocker.block():
526+ ...
527+
528+ This fixture is also used internally by pytest-django.
520529 """
521530 if not django_settings_is_configured ():
522531 return None
@@ -798,8 +807,8 @@ def __init__(self, *, _ispytest: bool = False) -> None:
798807 def _dj_db_wrapper (self ) -> django .db .backends .base .base .BaseDatabaseWrapper :
799808 from django .db .backends .base .base import BaseDatabaseWrapper
800809
801- # The first time the _dj_db_wrapper is accessed, we will save a
802- # reference to the real implementation.
810+ # The first time the _dj_db_wrapper is accessed, save a reference to the
811+ # real implementation.
803812 if self ._real_ensure_connection is None :
804813 self ._real_ensure_connection = BaseDatabaseWrapper .ensure_connection
805814
0 commit comments