1
0
mirror of https://github.com/django/django.git synced 2025-07-06 02:39:12 +00:00

[4.1.x] Fixed thread termination in servers.tests.LiveServerPort on Python 3.10.9+, 3.11.1+, and 3.12+.

Class cleanups registered in TestCase subclasses are no longer called
as TestCase.doClassCleanups() only cleans up the particular class, see

c2102136be
Backport of d02a9f0cee84e3d23f676bdf2ab6aadbf4a5bfe8 from main
This commit is contained in:
Mariusz Felisiak 2023-01-12 06:04:10 +01:00
parent 420f3230a2
commit 7ebcda3331

View File

@ -351,12 +351,15 @@ class LiveServerPort(LiveServerBase):
return return
# Unexpected error. # Unexpected error.
raise raise
self.assertNotEqual( try:
self.live_server_url, self.assertNotEqual(
TestCase.live_server_url, self.live_server_url,
f"Acquired duplicate server addresses for server threads: " TestCase.live_server_url,
f"{self.live_server_url}", f"Acquired duplicate server addresses for server threads: "
) f"{self.live_server_url}",
)
finally:
TestCase.doClassCleanups()
def test_specified_port_bind(self): def test_specified_port_bind(self):
"""LiveServerTestCase.port customizes the server's port.""" """LiveServerTestCase.port customizes the server's port."""
@ -367,12 +370,15 @@ class LiveServerPort(LiveServerBase):
TestCase.port = s.getsockname()[1] TestCase.port = s.getsockname()[1]
s.close() s.close()
TestCase._start_server_thread() TestCase._start_server_thread()
self.assertEqual( try:
TestCase.port, self.assertEqual(
TestCase.server_thread.port, TestCase.port,
f"Did not use specified port for LiveServerTestCase thread: " TestCase.server_thread.port,
f"{TestCase.port}", f"Did not use specified port for LiveServerTestCase thread: "
) f"{TestCase.port}",
)
finally:
TestCase.doClassCleanups()
class LiveServerThreadedTests(LiveServerBase): class LiveServerThreadedTests(LiveServerBase):