Skip to content

Commit f2b7a93

Browse files
committed
Lock/unlock of db breaks if pytest is executed twice in the same process
1 parent 1157a7c commit f2b7a93

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

pytest_django/plugin.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -800,8 +800,9 @@ def _dj_db_wrapper(self) -> django.db.backends.base.base.BaseDatabaseWrapper:
800800

801801
# The first time the _dj_db_wrapper is accessed, we will save a
802802
# reference to the real implementation.
803-
if self._real_ensure_connection is None:
804-
self._real_ensure_connection = BaseDatabaseWrapper.ensure_connection
803+
if not hasattr(BaseDatabaseWrapper, "_real_ensure_connection"):
804+
BaseDatabaseWrapper._real_ensure_connection = BaseDatabaseWrapper.ensure_connection
805+
self._real_ensure_connection = BaseDatabaseWrapper._real_ensure_connection
805806

806807
return BaseDatabaseWrapper
807808

0 commit comments

Comments
 (0)