@@ -522,23 +522,25 @@ def _django_setup_unittest(request, django_db_blocker):
522
522
523
523
cls = request .node .cls
524
524
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) .
526
526
# 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
+ )
533
535
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 ()
539
541
540
- orig_debug = cls .debug
541
- cls .debug = _cleaning_debug
542
+ orig_debug = cls .debug
543
+ cls .debug = _cleaning_debug
542
544
543
545
with django_db_blocker .unblock ():
544
546
if _handle_unittest_methods :
@@ -553,7 +555,8 @@ def _cleaning_debug(self):
553
555
else :
554
556
yield
555
557
556
- cls .debug = orig_debug
558
+ if monkeypatch_debug :
559
+ cls .debug = orig_debug
557
560
558
561
559
562
@pytest .fixture (scope = "function" , autouse = True )
0 commit comments