summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2023-01-12 06:04:10 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2023-01-12 06:06:24 +0100
commit7ebcda333138d4d118a40f3b10f4b87bf17356d1 (patch)
tree1310033790ee97baf28cf502f55b86a704424b7a
parent420f3230a229ee5602025724774a768838b94fac (diff)
[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 https://github.com/python/cpython/commit/c2102136be569e6fc8ed90181f229b46d07142f8 Backport of d02a9f0cee84e3d23f676bdf2ab6aadbf4a5bfe8 from main
-rw-r--r--tests/servers/tests.py30
1 files changed, 18 insertions, 12 deletions
diff --git a/tests/servers/tests.py b/tests/servers/tests.py
index 480bc827c1..47e7ceec16 100644
--- a/tests/servers/tests.py
+++ b/tests/servers/tests.py
@@ -351,12 +351,15 @@ class LiveServerPort(LiveServerBase):
return
# Unexpected error.
raise
- self.assertNotEqual(
- self.live_server_url,
- TestCase.live_server_url,
- f"Acquired duplicate server addresses for server threads: "
- f"{self.live_server_url}",
- )
+ try:
+ self.assertNotEqual(
+ self.live_server_url,
+ TestCase.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):
"""LiveServerTestCase.port customizes the server's port."""
@@ -367,12 +370,15 @@ class LiveServerPort(LiveServerBase):
TestCase.port = s.getsockname()[1]
s.close()
TestCase._start_server_thread()
- self.assertEqual(
- TestCase.port,
- TestCase.server_thread.port,
- f"Did not use specified port for LiveServerTestCase thread: "
- f"{TestCase.port}",
- )
+ try:
+ self.assertEqual(
+ TestCase.port,
+ TestCase.server_thread.port,
+ f"Did not use specified port for LiveServerTestCase thread: "
+ f"{TestCase.port}",
+ )
+ finally:
+ TestCase.doClassCleanups()
class LiveServerThreadedTests(LiveServerBase):