From 062ab4e52a8aed45ed191abac2225f65fbb65f33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20Hovm=C3=B6ller?= Date: Sat, 28 Sep 2024 19:26:55 +0200 Subject: [PATCH] Lock/unlock of db breaks if pytest is executed twice in the same process (fixes #1147) --- pytest_django/plugin.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pytest_django/plugin.py b/pytest_django/plugin.py index 62fa1791..36307e97 100644 --- a/pytest_django/plugin.py +++ b/pytest_django/plugin.py @@ -476,6 +476,13 @@ def get_order_number(test: pytest.Item) -> int: items.sort(key=get_order_number) +def pytest_unconfigure(config: pytest.Config) -> None: + if blocking_manager_key not in config.stash: + return + blocking_manager = config.stash[blocking_manager_key] + blocking_manager.unblock() + + @pytest.fixture(autouse=True, scope="session") def django_test_environment(request: pytest.FixtureRequest) -> Generator[None, None, None]: """Setup Django's test environment for the testing session.