@@ -522,23 +522,25 @@ def _django_setup_unittest(request, django_db_blocker):
522522
523523 cls = request .node .cls
524524
525- # Implement missing (as of 2.2) debug() wrapper/method for Django's TestCase.
525+ # Implement missing debug() wrapper/method for Django's TestCase (< 3.1.0) .
526526 # See pytest-dev/pytest-django#406.
527- # Pending PR for Django: https://github.com/django/django/pull/7436.
528- def _cleaning_debug (self ):
529- testMethod = getattr (self , self ._testMethodName )
530- skipped = getattr (self .__class__ , "__unittest_skip__" , False ) or getattr (
531- testMethod , "__unittest_skip__" , False
532- )
527+ import django
528+ monkeypatch_debug = django .VERSION < (3 , 1 )
529+ if monkeypatch_debug :
530+ def _cleaning_debug (self ):
531+ testMethod = getattr (self , self ._testMethodName )
532+ skipped = getattr (self .__class__ , "__unittest_skip__" , False ) or getattr (
533+ testMethod , "__unittest_skip__" , False
534+ )
533535
534- if not skipped :
535- self ._pre_setup ()
536- super (cls , self ).debug ()
537- if not skipped :
538- self ._post_teardown ()
536+ if not skipped :
537+ self ._pre_setup ()
538+ super (cls , self ).debug ()
539+ if not skipped :
540+ self ._post_teardown ()
539541
540- orig_debug = cls .debug
541- cls .debug = _cleaning_debug
542+ orig_debug = cls .debug
543+ cls .debug = _cleaning_debug
542544
543545 with django_db_blocker .unblock ():
544546 if _handle_unittest_methods :
@@ -553,7 +555,8 @@ def _cleaning_debug(self):
553555 else :
554556 yield
555557
556- cls .debug = orig_debug
558+ if monkeypatch_debug :
559+ cls .debug = orig_debug
557560
558561
559562@pytest .fixture (scope = "function" , autouse = True )
0 commit comments