#32437: LiveServerTestCase.setUpClass() doesn't clean up fully on failure
-------------------------------------+-------------------------------------
     Reporter:  Chris Jerdonek       |                    Owner:  Chris
                                     |  Jerdonek
         Type:  Bug                  |                   Status:  assigned
    Component:  Testing framework    |                  Version:  2.2
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:
  LiveServerTestCase,setUpClass      |  Unreviewed
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Description changed by Chris Jerdonek:

Old description:

> While working on #32417, I noticed in
> [https://code.djangoproject.com/ticket/32417#comment:6 this comment] that
> `LiveServerTestCase.setUpClass()` doesn't clean up all the way if
> `setUpClass()` errors out.
>
> Specifically, `LiveServerTestCase.setUpClass()`
> [https://github.com/django/django/blob/0963f184abd96800b76b19a6a181e1b544c7fafe/django/test/testcases.py#L1543-L1547
> looks like] this:
>
> {{{#!python
> @classmethod
> def setUpClass(cls):
>     super().setUpClass()
>     ...
>     cls._live_server_modified_settings = modify_settings(
>         ALLOWED_HOSTS={'append': cls.allowed_host},
>     )
>     ...
>     if cls.server_thread.error:
>         # Clean up behind ourselves, since tearDownClass won't get called
> in
>         # case of errors.
>         cls._tearDownClassInternal()
>         raise cls.server_thread.error
> }}}
>
> But `_tearDownClassInternal()`
> [https://github.com/django/django/blob/0963f184abd96800b76b19a6a181e1b544c7fafe/django/test/testcases.py#L1559-L1568
> doesn't undo] the call to `modify_settings()`.
>
> I will post a PR shortly.

New description:

 While working on #32417, I noticed in
 [https://code.djangoproject.com/ticket/32417#comment:6 this comment] that
 `LiveServerTestCase.setUpClass()` doesn't clean up all the way if
 `setUpClass()` errors out.

 Specifically, `LiveServerTestCase.setUpClass()`
 
[https://github.com/django/django/blob/0963f184abd96800b76b19a6a181e1b544c7fafe/django/test/testcases.py#L1543-L1547
 looks like] this:

 {{{#!python
 @classmethod
 def setUpClass(cls):
     super().setUpClass()
     ...
     cls._live_server_modified_settings = modify_settings(
         ALLOWED_HOSTS={'append': cls.allowed_host},
     )
     cls._live_server_modified_settings.enable()
     ...
     if cls.server_thread.error:
         # Clean up behind ourselves, since tearDownClass won't get called
 in
         # case of errors.
         cls._tearDownClassInternal()
         raise cls.server_thread.error
 }}}

 But `_tearDownClassInternal()`
 
[https://github.com/django/django/blob/0963f184abd96800b76b19a6a181e1b544c7fafe/django/test/testcases.py#L1559-L1568
 doesn't undo] the call to `cls._live_server_modified_settings.enable()`.

 I will post a PR shortly.

--

-- 
Ticket URL: <https://code.djangoproject.com/ticket/32437#comment:2>
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/067.e26cebdc9f84c8d3863f453fad86acb2%40djangoproject.com.

Reply via email to