Skip to content

Commit ec9741d

Browse files
authored
Merge pull request #740 from blueyed/unittest
Revisit unittest handling
2 parents 909dc81 + 63abadf commit ec9741d

File tree

1 file changed

+23
-24
lines changed

1 file changed

+23
-24
lines changed

pytest_django/plugin.py

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -512,43 +512,42 @@ def _django_db_marker(request):
512512
@pytest.fixture(autouse=True, scope="class")
513513
def _django_setup_unittest(request, django_db_blocker):
514514
"""Setup a django unittest, internal to pytest-django."""
515-
if django_settings_is_configured() and is_django_unittest(request):
516-
request.getfixturevalue("django_test_environment")
517-
request.getfixturevalue("django_db_setup")
515+
if not django_settings_is_configured() or not is_django_unittest(request):
516+
yield
517+
return
518518

519-
django_db_blocker.unblock()
519+
request.getfixturevalue("django_db_setup")
520520

521-
cls = request.node.cls
521+
cls = request.node.cls
522522

523-
# implement missing (as of 1.10) debug() method for django's TestCase
524-
# see pytest-dev/pytest-django#406
525-
def _cleaning_debug(self):
526-
testMethod = getattr(self, self._testMethodName)
527-
skipped = getattr(self.__class__, "__unittest_skip__", False) or getattr(
528-
testMethod, "__unittest_skip__", False
529-
)
523+
# implement missing (as of 1.10) debug() method for django's TestCase
524+
# see pytest-dev/pytest-django#406
525+
def _cleaning_debug(self):
526+
testMethod = getattr(self, self._testMethodName)
527+
skipped = getattr(self.__class__, "__unittest_skip__", False) or getattr(
528+
testMethod, "__unittest_skip__", False
529+
)
530530

531-
if not skipped:
532-
self._pre_setup()
533-
super(cls, self).debug()
534-
if not skipped:
535-
self._post_teardown()
531+
if not skipped:
532+
self._pre_setup()
533+
super(cls, self).debug()
534+
if not skipped:
535+
self._post_teardown()
536536

537-
cls.debug = _cleaning_debug
537+
cls.debug = _cleaning_debug
538538

539+
with django_db_blocker.unblock():
539540
if _handle_unittest_methods:
540541
_restore_class_methods(cls)
541542
cls.setUpClass()
542543
_disable_class_methods(cls)
543544

544-
def teardown():
545-
_restore_class_methods(cls)
546-
cls.tearDownClass()
547-
django_db_blocker.restore()
545+
yield
548546

549-
request.addfinalizer(teardown)
547+
_restore_class_methods(cls)
548+
cls.tearDownClass()
550549
else:
551-
request.addfinalizer(django_db_blocker.restore)
550+
yield
552551

553552

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

0 commit comments

Comments
 (0)