From c010be1a0296640878a3d0d1b8285c09e3fae5ce Mon Sep 17 00:00:00 2001 From: grossmj Date: Thu, 23 Jul 2026 18:00:11 +0200 Subject: [PATCH] feat(tests): increase maximum open file descriptors for test runs on Unix --- tests/conftest.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/conftest.py b/tests/conftest.py index 4c6ba0525..7271179a0 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -8,6 +8,8 @@ import uuid import configparser import base64 import stat +import resource +import platform from fastapi import FastAPI from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine @@ -35,6 +37,19 @@ sys._called_from_test = True sys.original_platform = sys.platform +def pytest_configure(config): + """ + Increases the maximum number of open file descriptors before running tests (Unix only). + """ + + if platform.system() != "Windows": + soft, hard = resource.getrlimit(resource.RLIMIT_NOFILE) + # Set soft limit to hard limit, or a safe high number like 4096 + new_soft = min(4096, hard) + if soft < new_soft: + resource.setrlimit(resource.RLIMIT_NOFILE, (new_soft, hard)) + + @pytest_asyncio.fixture(loop_scope="class", scope="class") async def app() -> AsyncGenerator[Any, Any]: