@@ -512,43 +512,42 @@ def _django_db_marker(request):
512
512
@pytest .fixture (autouse = True , scope = "class" )
513
513
def _django_setup_unittest (request , django_db_blocker ):
514
514
"""Setup a django unittest, internal to pytest-django."""
515
- if django_settings_is_configured () and is_django_unittest (request ):
516
- request . getfixturevalue ( "django_test_environment" )
517
- request . getfixturevalue ( "django_db_setup" )
515
+ if not django_settings_is_configured () or not is_django_unittest (request ):
516
+ yield
517
+ return
518
518
519
- django_db_blocker . unblock ( )
519
+ request . getfixturevalue ( "django_db_setup" )
520
520
521
- cls = request .node .cls
521
+ cls = request .node .cls
522
522
523
- # implement missing (as of 1.10) debug() method for django's TestCase
524
- # see pytest-dev/pytest-django#406
525
- def _cleaning_debug (self ):
526
- testMethod = getattr (self , self ._testMethodName )
527
- skipped = getattr (self .__class__ , "__unittest_skip__" , False ) or getattr (
528
- testMethod , "__unittest_skip__" , False
529
- )
523
+ # implement missing (as of 1.10) debug() method for django's TestCase
524
+ # see pytest-dev/pytest-django#406
525
+ def _cleaning_debug (self ):
526
+ testMethod = getattr (self , self ._testMethodName )
527
+ skipped = getattr (self .__class__ , "__unittest_skip__" , False ) or getattr (
528
+ testMethod , "__unittest_skip__" , False
529
+ )
530
530
531
- if not skipped :
532
- self ._pre_setup ()
533
- super (cls , self ).debug ()
534
- if not skipped :
535
- self ._post_teardown ()
531
+ if not skipped :
532
+ self ._pre_setup ()
533
+ super (cls , self ).debug ()
534
+ if not skipped :
535
+ self ._post_teardown ()
536
536
537
- cls .debug = _cleaning_debug
537
+ cls .debug = _cleaning_debug
538
538
539
+ with django_db_blocker .unblock ():
539
540
if _handle_unittest_methods :
540
541
_restore_class_methods (cls )
541
542
cls .setUpClass ()
542
543
_disable_class_methods (cls )
543
544
544
- def teardown ():
545
- _restore_class_methods (cls )
546
- cls .tearDownClass ()
547
- django_db_blocker .restore ()
545
+ yield
548
546
549
- request .addfinalizer (teardown )
547
+ _restore_class_methods (cls )
548
+ cls .tearDownClass ()
550
549
else :
551
- request . addfinalizer ( django_db_blocker . restore )
550
+ yield
552
551
553
552
554
553
@pytest .fixture (scope = "function" , autouse = True )
0 commit comments