#29024: `TestContextDecorator` never exits if `setUp` fails in tests
-------------------------------------+-------------------------------------
     Reporter:  Anthony King         |                    Owner:  Shahbaj
                                     |  Sayyad
         Type:  Bug                  |                   Status:  assigned
    Component:  Testing framework    |                  Version:  master
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:  Accepted
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  1                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Anthony King):

 Hi Shahbaj,

 I saw your post in the mailing list.


 So how we've done it internally is like this:

 {{{
 #!python

 class TestContextDecorator(DjangoTestContextDecorator):
     def decorate_class(self, cls):
         # https://code.djangoproject.com/ticket/29024

         if issubclass(cls, TestCase):
             decorated_setUp = cls.setUp

             @wraps(decorated_setUp)
             def setUp(inner_self):
                 context = self.enable()
                 if self.attr_name:
                     setattr(inner_self, self.attr_name, context)
                 inner_self.addCleanup(self.disable)
                 decorated_setUp(inner_self)

             cls.setUp = setUp
             return cls
         raise TypeError('Can only decorate subclasses of
 unittest.TestCase')
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/29024#comment:4>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/067.905d96498d4948ef2badf453a567655b%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to