From 534895f1ace819053f28463fd62b833ba2ced829 Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Thu, 2 Feb 2023 13:09:15 +0100 Subject: [4.0.x] Fixed thread termination in servers.tests.LiveServerPort on Python < 3.10.9. TestCase.doClassCleanups() cannot be called on Python < 3.10.9 because setUpClass()/tearDownClass() are called multiple times in LiveServerTestCase tests (refs #27079). --- tests/servers/tests.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tests/servers/tests.py b/tests/servers/tests.py index 03496c3d2a..3358e21393 100644 --- a/tests/servers/tests.py +++ b/tests/servers/tests.py @@ -4,6 +4,7 @@ Tests for django.core.servers. import errno import os import socket +import sys import threading from http.client import HTTPConnection from urllib.error import HTTPError @@ -364,7 +365,11 @@ class LiveServerPort(LiveServerBase): % self.live_server_url, ) finally: - TestCase.doClassCleanups() + # Class cleanups registered in TestCase subclasses are no longer + # called as TestCase.doClassCleanups() only cleans up the + # particular class in Python 3.10.9+. + if sys.version_info >= (3, 10, 9): + TestCase.doClassCleanups() TestCase.tearDownClass() def test_specified_port_bind(self): @@ -384,7 +389,11 @@ class LiveServerPort(LiveServerBase): % TestCase.port, ) finally: - TestCase.doClassCleanups() + # Class cleanups registered in TestCase subclasses are no longer + # called as TestCase.doClassCleanups() only cleans up the + # particular class in Python 3.10.9+. + if sys.version_info >= (3, 10, 9): + TestCase.doClassCleanups() TestCase.tearDownClass() -- cgit v1.2.1