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.
--
Ticket URL: <https://code.djangoproject.com/ticket/32437>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* owner: nobody => Chris Jerdonek
* status: new => assigned
* has_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/32437#comment:1>
Old description:
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>
* cc: Florian Apolloner, Tobias McNulty (added)
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/32437#comment:3>
Comment (by Florian Apolloner):
The cleanup precedes the commit that modified the settings by three years
(https://github.com/django/django/commit/17e661641ddaf8266e7430d83cfb2039abc55df7
&
https://github.com/django/django/commit/73a610d2a81bc3bf2d3834786b2458bc85953ed0)
so it is more than likely that this was just an oversight at the time.
I'll give the PR a review in a second.
--
Ticket URL: <https://code.djangoproject.com/ticket/32437#comment:4>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/32437#comment:5>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"694deff82f86e025561dfa724425f67e2ff7cbb7" 694deff8]:
{{{
#!CommitTicketReference repository=""
revision="694deff82f86e025561dfa724425f67e2ff7cbb7"
Fixed #32437 -- Fixed cleaning up ALLOWED_HOSTS in LiveServerTestCase on
setUpClass() failure.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/32437#comment:6>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"65a620948c38c6ac6c7d93e79f70590331bcb2d0" 65a62094]:
{{{
#!CommitTicketReference repository=""
revision="65a620948c38c6ac6c7d93e79f70590331bcb2d0"
[3.2.x] Fixed #32437 -- Fixed cleaning up ALLOWED_HOSTS in
LiveServerTestCase on setUpClass() failure.
Backport of 694deff82f86e025561dfa724425f67e2ff7cbb7 from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/32437#comment:7>