Skip to content

Commit

Permalink
Merge pull request #740 from blueyed/unittest
Browse files Browse the repository at this point in the history
Revisit unittest handling
  • Loading branch information
blueyed authored May 30, 2019
2 parents 909dc81 + 63abadf commit ec9741d
Showing 1 changed file with 23 additions and 24 deletions.
47 changes: 23 additions & 24 deletions pytest_django/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,43 +512,42 @@ def _django_db_marker(request):
@pytest.fixture(autouse=True, scope="class")
def _django_setup_unittest(request, django_db_blocker):
"""Setup a django unittest, internal to pytest-django."""
if django_settings_is_configured() and is_django_unittest(request):
request.getfixturevalue("django_test_environment")
request.getfixturevalue("django_db_setup")
if not django_settings_is_configured() or not is_django_unittest(request):
yield
return

django_db_blocker.unblock()
request.getfixturevalue("django_db_setup")

cls = request.node.cls
cls = request.node.cls

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

if not skipped:
self._pre_setup()
super(cls, self).debug()
if not skipped:
self._post_teardown()
if not skipped:
self._pre_setup()
super(cls, self).debug()
if not skipped:
self._post_teardown()

cls.debug = _cleaning_debug
cls.debug = _cleaning_debug

with django_db_blocker.unblock():
if _handle_unittest_methods:
_restore_class_methods(cls)
cls.setUpClass()
_disable_class_methods(cls)

def teardown():
_restore_class_methods(cls)
cls.tearDownClass()
django_db_blocker.restore()
yield

request.addfinalizer(teardown)
_restore_class_methods(cls)
cls.tearDownClass()
else:
request.addfinalizer(django_db_blocker.restore)
yield


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

0 comments on commit ec9741d

Please sign in to comment.