[test:networking] Fix logging handler removal test (#17379)

Ref: https://github.com/python/cpython/issues/79366

Authored by: doe1080
This commit is contained in:
doe1080
2026-08-15 19:52:26 +00:00
committed by GitHub
parent 5d6b8c8cd1
commit 3128f6a433
+6 -6
View File
@@ -859,15 +859,15 @@ class TestRequestHandlerMisc:
('Websockets', 'websockets.server'), ('Websockets', 'websockets.server'),
], indirect=['handler']) ], indirect=['handler'])
def test_remove_logging_handler(self, handler, logger_name): def test_remove_logging_handler(self, handler, logger_name):
# Ensure any logging handlers, which may contain a YoutubeDL instance, # Ensure closing the request handler removes only its logging handlers,
# are removed when we close the request handler # which may reference a YoutubeDL instance
# See: https://github.com/yt-dlp/yt-dlp/issues/8922 # See: https://github.com/yt-dlp/yt-dlp/issues/8922
logging_handlers = logging.getLogger(logger_name).handlers logger = logging.getLogger(logger_name)
before_count = len(logging_handlers) original_handlers = logger.handlers.copy()
rh = handler() rh = handler()
assert len(logging_handlers) == before_count + 1 assert len(logger.handlers) == len(original_handlers) + 1
rh.close() rh.close()
assert len(logging_handlers) == before_count assert logger.handlers == original_handlers
def test_wrap_request_errors(self): def test_wrap_request_errors(self):
class TestRequestHandler(RequestHandler): class TestRequestHandler(RequestHandler):