Merge pull request #2828 from GNS3/set-ulimit-pytest

feat(tests): increase maximum open file descriptors for test runs on Unix
This commit is contained in:
Jeremy Grossmann 2026-07-23 18:05:19 +02:00 committed by GitHub
commit 28f883b46a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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]: