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:
477
477
478
478
479
479
def 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 ()
484
487
485
488
486
489
@pytest .fixture (autouse = True , scope = "session" )
@@ -852,6 +855,11 @@ def restore(self) -> None:
852
855
"""
853
856
self ._dj_db_wrapper .ensure_connection = self ._history .pop ()
854
857
858
+ @property
859
+ def is_active (self ) -> bool :
860
+ """Whether a block() or unblock() is currently active."""
861
+ return bool (self ._history )
862
+
855
863
856
864
# On Config.stash.
857
865
blocking_manager_key = pytest .StashKey [DjangoDbBlocker ]()
You can’t perform that action at this time.
0 commit comments