File tree Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -477,10 +477,13 @@ def get_order_number(test: pytest.Item) -> int:
477477
478478
479479def pytest_unconfigure (config : pytest .Config ) -> None :
480- if blocking_manager_key not in config .stash :
481- return
482- blocking_manager = config .stash [blocking_manager_key ]
483- blocking_manager .unblock ()
480+ # Undo the block() in _setup_django(), if it happenned.
481+ # It's also possible the user forgot to call restore().
482+ # We can warn about it, but let's just clean it up.
483+ if blocking_manager_key in config .stash :
484+ blocking_manager = config .stash [blocking_manager_key ]
485+ while blocking_manager .is_active :
486+ blocking_manager .restore ()
484487
485488
486489@pytest .fixture (autouse = True , scope = "session" )
@@ -852,6 +855,11 @@ def restore(self) -> None:
852855 """
853856 self ._dj_db_wrapper .ensure_connection = self ._history .pop ()
854857
858+ @property
859+ def is_active (self ) -> bool :
860+ """Whether a block() or unblock() is currently active."""
861+ return bool (self ._history )
862+
855863
856864# On Config.stash.
857865blocking_manager_key = pytest .StashKey [DjangoDbBlocker ]()
You can’t perform that action at this time.
0 commit comments