Skip to content

Commit 63abadf

Browse files
committed
_django_setup_unittest: use django_db_blocker contextmanager
1 parent 90d0f6c commit 63abadf

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

pytest_django/plugin.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -513,12 +513,11 @@ def _django_db_marker(request):
513513
def _django_setup_unittest(request, django_db_blocker):
514514
"""Setup a django unittest, internal to pytest-django."""
515515
if not django_settings_is_configured() or not is_django_unittest(request):
516+
yield
516517
return
517518

518519
request.getfixturevalue("django_db_setup")
519520

520-
django_db_blocker.unblock()
521-
522521
cls = request.node.cls
523522

524523
# implement missing (as of 1.10) debug() method for django's TestCase
@@ -537,19 +536,18 @@ def _cleaning_debug(self):
537536

538537
cls.debug = _cleaning_debug
539538

540-
if _handle_unittest_methods:
541-
_restore_class_methods(cls)
542-
cls.setUpClass()
543-
_disable_class_methods(cls)
539+
with django_db_blocker.unblock():
540+
if _handle_unittest_methods:
541+
_restore_class_methods(cls)
542+
cls.setUpClass()
543+
_disable_class_methods(cls)
544+
545+
yield
544546

545-
def teardown():
546547
_restore_class_methods(cls)
547548
cls.tearDownClass()
548-
django_db_blocker.restore()
549-
550-
request.addfinalizer(teardown)
551-
else:
552-
request.addfinalizer(django_db_blocker.restore)
549+
else:
550+
yield
553551

554552

555553
@pytest.fixture(scope="function", autouse=True)

0 commit comments

Comments
 (0)