summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2023-02-02 13:09:15 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2023-02-02 13:13:25 +0100
commit534895f1ace819053f28463fd62b833ba2ced829 (patch)
tree026e0f7f7053aa02bdf9c252137b34477c309beb
parentd0659443537959e1b4498cc718a03b1cc7e4cc9b (diff)
downloaddjango-534895f1ace819053f28463fd62b833ba2ced829.tar.gz
[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).
-rw-r--r--tests/servers/tests.py13
1 files 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()