1
0
mirror of https://github.com/django/django.git synced 2025-07-07 11:19:12 +00:00

[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).
This commit is contained in:
Mariusz Felisiak 2023-02-02 13:09:15 +01:00
parent d065944353
commit 534895f1ac

View File

@ -4,6 +4,7 @@ Tests for django.core.servers.
import errno import errno
import os import os
import socket import socket
import sys
import threading import threading
from http.client import HTTPConnection from http.client import HTTPConnection
from urllib.error import HTTPError from urllib.error import HTTPError
@ -364,6 +365,10 @@ class LiveServerPort(LiveServerBase):
% self.live_server_url, % self.live_server_url,
) )
finally: finally:
# 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.doClassCleanups()
TestCase.tearDownClass() TestCase.tearDownClass()
@ -384,6 +389,10 @@ class LiveServerPort(LiveServerBase):
% TestCase.port, % TestCase.port,
) )
finally: finally:
# 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.doClassCleanups()
TestCase.tearDownClass() TestCase.tearDownClass()