From 8a119ff3e4e80f6d0cbecf2e81477641f3fa5cac Mon Sep 17 00:00:00 2001 From: Adam Harwell Date: Wed, 11 Nov 2026 21:26:23 -0500 Subject: [PATCH] Make the high fd test really disable garbage collection test_high_number_of_file_descriptors needs the server to accept its connection on a file descriptor above the limit, so nothing may free a lower one while it runs. Its _garbage_bin fixture was meant to stop garbage collection, but pypytools' DefaultGc.nogc() only pauses the collections that DefaultGc's own hooks start. Nothing enables those hooks, and CPython has none to install, so the interpreter's collector kept running. This matters once stopped servers can be collected (#858): a collection then closes the open sockets of test clients that fixtures attached to a server, and the server can take one of the freed low file descriptors. That failed the test once on CPython 3.14 in CI. The fixture now disables the collector through the gc module, which CPython and PyPy both support, and turns it back on afterwards. A fixture's code after its yield runs even when the test fails, so it needs no try/finally. Nothing else uses pypytools, so drop it from the test dependencies and from the pylint hook's environment. The lock files still pin it until they are regenerated. Assisted-By: Anthropic Claude Opus 5.5 Signed-off-by: Adam Harwell --- .pre-commit-config.yaml | 1 - cheroot/test/test_server.py | 7 ++++--- dependencies/direct/py.in | 5 ----- docs/changelog-fragments.d/880.contrib.rst | 9 +++++++++ 4 files changed, 13 insertions(+), 9 deletions(-) create mode 100644 docs/changelog-fragments.d/880.contrib.rst diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d66bcb01ac..a723effe40 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -332,7 +332,6 @@ repos: - portend - pylint-pytest ~= 2.0.0a0 - pyOpenSSL # needed by pylint-pytest since it picks up pytest's args - - pypytools - pytest-cov # needed by pylint-pytest since it picks up pytest's args - pytest-mock # needed by pylint-pytest since it picks up pytest's args - >- # needed by pylint-pytest since it picks up pytest's args diff --git a/cheroot/test/test_server.py b/cheroot/test/test_server.py index ae6e390a44..11c47231fa 100644 --- a/cheroot/test/test_server.py +++ b/cheroot/test/test_server.py @@ -1,5 +1,6 @@ """Tests for the HTTP server.""" +import gc import os import pathlib import queue @@ -17,7 +18,6 @@ import requests import requests_unixsocket -from pypytools.gc.custom import DefaultGc from .._compat import IS_LINUX, IS_MACOS, IS_WINDOWS, SYS_PLATFORM, bton, ntob from ..server import IS_UID_GID_RESOLVABLE, Gateway, HTTPServer @@ -418,8 +418,9 @@ def test_reuse_port(http_server, ip_addr, mocker): @pytest.fixture def _garbage_bin(): """Disable garbage collection when this fixture is in use.""" - with DefaultGc().nogc(): - yield + gc.disable() + yield + gc.enable() @pytest.fixture diff --git a/dependencies/direct/py.in b/dependencies/direct/py.in index 486e8fcadd..6a5ec097d6 100644 --- a/dependencies/direct/py.in +++ b/dependencies/direct/py.in @@ -23,11 +23,6 @@ portend pyopenssl -# The pypytools library provides a cross-implementation context -# manager for disabling garbage collection in specific blocks -# of the control flow: -pypytools - pytest-clarity pytest-cov pytest-mock >= 1.11.0 diff --git a/docs/changelog-fragments.d/880.contrib.rst b/docs/changelog-fragments.d/880.contrib.rst new file mode 100644 index 0000000000..97766ab44d --- /dev/null +++ b/docs/changelog-fragments.d/880.contrib.rst @@ -0,0 +1,9 @@ +Made the test of high file descriptor numbers disable garbage +collection while it runs, as its fixture intended: the +:pypi:`pypytools` context manager that it used only pauses the +collections that :pypi:`pypytools` starts itself, so the interpreter's +collector kept running and could free a low file descriptor for the +server to take. Nothing else used :pypi:`pypytools`, so it is no +longer a test dependency. + +-- by :user:`rm-you`