feat(tests): increase maximum open file descriptors for test runs on Unix

This commit is contained in:
grossmj 2026-07-23 18:00:11 +02:00
parent 2b949b1a77
commit c010be1a02
No known key found for this signature in database
GPG Key ID: 1E7DD6DBB53FF3D7

View File

@ -8,6 +8,8 @@ import uuid
import configparser import configparser
import base64 import base64
import stat import stat
import resource
import platform
from fastapi import FastAPI from fastapi import FastAPI
from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine
@ -35,6 +37,19 @@ sys._called_from_test = True
sys.original_platform = sys.platform 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") @pytest_asyncio.fixture(loop_scope="class", scope="class")
async def app() -> AsyncGenerator[Any, Any]: async def app() -> AsyncGenerator[Any, Any]: