@@ -512,43 +512,45 @@ def _django_db_marker(request):
512512@pytest .fixture (autouse = True , scope = "class" )
513513def _django_setup_unittest (request , django_db_blocker ):
514514 """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+ return
518517
519- django_db_blocker .unblock ()
518+ request .getfixturevalue ("django_test_environment" )
519+ request .getfixturevalue ("django_db_setup" )
520520
521- cls = request . node . cls
521+ django_db_blocker . unblock ()
522522
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+ cls = request .node .cls
530524
531- if not skipped :
532- self ._pre_setup ()
533- super (cls , self ).debug ()
534- if not skipped :
535- self ._post_teardown ()
525+ # implement missing (as of 1.10) debug() method for django's TestCase
526+ # see pytest-dev/pytest-django#406
527+ def _cleaning_debug (self ):
528+ testMethod = getattr (self , self ._testMethodName )
529+ skipped = getattr (self .__class__ , "__unittest_skip__" , False ) or getattr (
530+ testMethod , "__unittest_skip__" , False
531+ )
536532
537- cls .debug = _cleaning_debug
533+ if not skipped :
534+ self ._pre_setup ()
535+ super (cls , self ).debug ()
536+ if not skipped :
537+ self ._post_teardown ()
538538
539- if _handle_unittest_methods :
540- _restore_class_methods (cls )
541- cls .setUpClass ()
542- _disable_class_methods (cls )
539+ cls .debug = _cleaning_debug
543540
544- def teardown () :
545- _restore_class_methods (cls )
546- cls .tearDownClass ()
547- django_db_blocker . restore ( )
541+ if _handle_unittest_methods :
542+ _restore_class_methods (cls )
543+ cls .setUpClass ()
544+ _disable_class_methods ( cls )
548545
549- request .addfinalizer (teardown )
550- else :
551- request .addfinalizer (django_db_blocker .restore )
546+ def teardown ():
547+ _restore_class_methods (cls )
548+ cls .tearDownClass ()
549+ django_db_blocker .restore ()
550+
551+ request .addfinalizer (teardown )
552+ else :
553+ request .addfinalizer (django_db_blocker .restore )
552554
553555
554556@pytest .fixture (scope = "function" , autouse = True )
0 commit comments