@@ -518,29 +518,24 @@ def _django_setup_unittest(request, django_db_blocker):
518
518
yield
519
519
return
520
520
521
- request . getfixturevalue ( "django_db_setup" )
521
+ from _pytest . unittest import TestCaseFunction
522
522
523
- cls = request .node .cls
523
+ if "debug" in TestCaseFunction .runtest .__code__ .co_names :
524
+ # Fix pytest (https://github.com/pytest-dev/pytest/issues/5991), only
525
+ # if "self._testcase.debug()" is being used (forward compatible).
526
+ from _pytest .monkeypatch import MonkeyPatch
524
527
525
- # Implement missing debug() wrapper/method for Django's TestCase (< 3.1.0).
526
- # See pytest-dev/pytest-django#406.
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
- )
528
+ def non_debugging_runtest (self ):
529
+ self ._testcase (result = self )
535
530
536
- if not skipped :
537
- self ._pre_setup ()
538
- super (cls , self ).debug ()
539
- if not skipped :
540
- self ._post_teardown ()
531
+ mp_debug = MonkeyPatch ()
532
+ mp_debug .setattr ("_pytest.unittest.TestCaseFunction.runtest" , non_debugging_runtest )
533
+ else :
534
+ mp_debug = None
541
535
542
- orig_debug = cls .debug
543
- cls .debug = _cleaning_debug
536
+ request .getfixturevalue ("django_db_setup" )
537
+
538
+ cls = request .node .cls
544
539
545
540
with django_db_blocker .unblock ():
546
541
if _handle_unittest_methods :
@@ -555,8 +550,8 @@ def _cleaning_debug(self):
555
550
else :
556
551
yield
557
552
558
- if monkeypatch_debug :
559
- cls . debug = orig_debug
553
+ if mp_debug :
554
+ mp_debug . undo ()
560
555
561
556
562
557
@pytest .fixture (scope = "function" , autouse = True )
0 commit comments