File tree 2 files changed +37
-2
lines changed
2 files changed +37
-2
lines changed Original file line number Diff line number Diff line change @@ -522,8 +522,9 @@ def _django_setup_unittest(request, django_db_blocker):
522
522
523
523
cls = request .node .cls
524
524
525
- # implement missing (as of 1.10) debug() method for django's TestCase
526
- # see pytest-dev/pytest-django#406
525
+ # Implement missing (as of 2.2) debug() wrapper/method for Django's TestCase.
526
+ # See pytest-dev/pytest-django#406.
527
+ # Pending PR for Django: https://github.com/django/django/pull/7436.
527
528
def _cleaning_debug (self ):
528
529
testMethod = getattr (self , self ._testMethodName )
529
530
skipped = getattr (self .__class__ , "__unittest_skip__" , False ) or getattr (
@@ -536,6 +537,7 @@ def _cleaning_debug(self):
536
537
if not skipped :
537
538
self ._post_teardown ()
538
539
540
+ orig_debug = cls .debug
539
541
cls .debug = _cleaning_debug
540
542
541
543
with django_db_blocker .unblock ():
@@ -551,6 +553,8 @@ def _cleaning_debug(self):
551
553
else :
552
554
yield
553
555
556
+ cls .debug = orig_debug
557
+
554
558
555
559
@pytest .fixture (scope = "function" , autouse = True )
556
560
def _dj_autoclear_mailbox ():
Original file line number Diff line number Diff line change @@ -456,3 +456,34 @@ def tearDown(self):
456
456
457
457
result = django_testdir .runpytest_subprocess ("-v" , "--pdb" )
458
458
assert result .ret == 0
459
+
460
+
461
+ def test_debug_restored (django_testdir ):
462
+ django_testdir .create_test_module (
463
+ """
464
+ from django.test import TestCase
465
+
466
+ pre_setup_count = 0
467
+
468
+
469
+ class TestClass1(TestCase):
470
+
471
+ def test_method(self):
472
+ pass
473
+
474
+
475
+ class TestClass2(TestClass1):
476
+
477
+ def _pre_setup(self):
478
+ global pre_setup_count
479
+ pre_setup_count += 1
480
+ super(TestClass2, self)._pre_setup()
481
+
482
+ def test_method(self):
483
+ assert pre_setup_count == 1
484
+ """
485
+ )
486
+
487
+ result = django_testdir .runpytest_subprocess ("--pdb" )
488
+ result .stdout .fnmatch_lines (["*= 2 passed in *" ])
489
+ assert result .ret == 0
You can’t perform that action at this time.
0 commit comments