@@ -462,7 +462,7 @@ def django_test_environment(request):
462462
463463
464464@pytest .fixture (scope = "session" ) 
465- def  django_db_blocker ():
465+ def  _django_db_blocker ():
466466    """Wrapper around Django's database access. 
467467
468468    This object can be used to re-enable database access.  This fixture is used 
@@ -481,6 +481,28 @@ def django_db_blocker():
481481    return  _blocking_manager 
482482
483483
484+ @pytest .fixture (scope = "session" ) 
485+ def  django_db_blocker (django_db_setup , _django_db_blocker ):
486+     """Wrapper around _django_db_blocker to serve as convenience reference. 
487+ 
488+     The ``_django_db_blocker`` fixture must be available for the ``django_db_setup`` 
489+     fixture, so ``django_db_setup`` must request the ``_django_db_blocker`` fixture. But 
490+     in order for ``_django_db_blocker`` to be used, ``django_db_setup`` must also have 
491+     been executed, suggesting that ``_django_db_blocker`` should request 
492+     ``django_db_setup``, especially since it is possible for ``_django_db_blocker`` to 
493+     be needed when ``django_db_setup`` wouldn't normally have been run (e.g. if a test 
494+     isn't marked with ``pytest.mark.django_db``). 
495+ 
496+     This would normally cause a catch-22, but to circumvent this, the 
497+     `_django_db_blocker`` fixture is used behind the scenes, while ``django_db_blocker`` 
498+     serves as the fixture used by everything that would normally need the blocker (aside 
499+     from ``django_db_setup``). This fixture helps coordinate between both 
500+     ``django_db_setup`` and ``_django_db_blocker``, so that whenever 
501+     ``django_db_blocker`` gets used, it ensures ``django_db_setup`` is run first. 
502+     """ 
503+     return  _django_db_blocker 
504+ 
505+ 
484506@pytest .fixture (autouse = True ) 
485507def  _django_db_marker (request ):
486508    """Implement the django_db marker, internal to pytest-django. 
@@ -500,7 +522,7 @@ def _django_db_marker(request):
500522
501523
502524@pytest .fixture (autouse = True , scope = "class" ) 
503- def  _django_setup_unittest (request , django_db_blocker ):
525+ def  _django_setup_unittest (request , _django_db_blocker ):
504526    """Setup a django unittest, internal to pytest-django.""" 
505527    if  not  django_settings_is_configured () or  not  is_django_unittest (request ):
506528        yield 
@@ -525,7 +547,7 @@ def non_debugging_runtest(self):
525547
526548    cls  =  request .node .cls 
527549
528-     with  django_db_blocker .unblock ():
550+     with  _django_db_blocker .unblock ():
529551        if  _handle_unittest_methods :
530552            _restore_class_methods (cls )
531553            cls .setUpClass ()
@@ -736,7 +758,7 @@ def __exit__(self, exc_type, exc_value, traceback):
736758class  _DatabaseBlocker (object ):
737759    """Manager for django.db.backends.base.base.BaseDatabaseWrapper. 
738760
739-     This is the object returned by django_db_blocker. 
761+     This is the object returned by _django_db_blocker and  django_db_blocker. 
740762    """ 
741763
742764    def  __init__ (self ):
0 commit comments