Skip to content

Django TestCase: skip patching debug() for Django 3.1 #773

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 18, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 18 additions & 15 deletions pytest_django/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,23 +522,25 @@ def _django_setup_unittest(request, django_db_blocker):

cls = request.node.cls

# Implement missing (as of 2.2) debug() wrapper/method for Django's TestCase.
# Implement missing debug() wrapper/method for Django's TestCase (< 3.1.0).
# See pytest-dev/pytest-django#406.
# Pending PR for Django: https://github.com/django/django/pull/7436.
def _cleaning_debug(self):
testMethod = getattr(self, self._testMethodName)
skipped = getattr(self.__class__, "__unittest_skip__", False) or getattr(
testMethod, "__unittest_skip__", False
)
import django
monkeypatch_debug = django.VERSION < (3, 1)
if monkeypatch_debug:
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()

orig_debug = cls.debug
cls.debug = _cleaning_debug
orig_debug = cls.debug
cls.debug = _cleaning_debug

with django_db_blocker.unblock():
if _handle_unittest_methods:
Expand All @@ -553,7 +555,8 @@ def _cleaning_debug(self):
else:
yield

cls.debug = orig_debug
if monkeypatch_debug:
cls.debug = orig_debug


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