From 05095a3bacb0a802e3ad1e448bb59b2d3180e190 Mon Sep 17 00:00:00 2001 From: Trenton Holmes <797416+stumpylog@users.noreply.github.com> Date: Fri, 10 Jan 2025 15:04:15 -0800 Subject: [PATCH] Resolves resource warnings on unclosed sockets --- pyproject.toml | 15 +++------------ tests/conftest.py | 11 +++++++---- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index cc5e3e0..afd050d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -68,28 +68,19 @@ installer = "uv" [tool.hatch.envs.hatch-static-analysis] # https://hatch.pypa.io/latest/config/internal/static-analysis/ -dependencies = [ "ruff ~= 0.8" ] +dependencies = [ "ruff ~= 0.9" ] config-path = "none" [tool.hatch.envs.hatch-test] # https://hatch.pypa.io/latest/config/internal/testing/ parallel = true randomize = true -dependencies = [ - "coverage-enable-subprocess == 1.0", - "coverage[toml] ~= 7.6", - "pytest ~= 8.3", - "pytest-mock ~= 3.14", - "pytest-randomly ~= 3.15", - "pytest-rerunfailures ~= 15.0", - "pytest-xdist[psutil] ~= 3.6", - "pytest-asyncio ~= 0.25", -] extra-dependencies = [ "pytest-sugar", "pytest-httpx ~= 0.33", "python-magic", "pytest-docker ~= 3.1", + "pytest-asyncio ~= 0.25", ] extra-args = [ "--maxprocesses=8", "--pythonwarnings=all" ] @@ -245,7 +236,7 @@ max_supported_python = "3.13" minversion = "8.0" testpaths = [ "tests" ] asyncio_mode = "auto" -asyncio_default_fixture_loop_scope = "session" +asyncio_default_fixture_loop_scope = "function" [tool.coverage.run] source_pkgs = [ "tika_client", "tests" ] diff --git a/tests/conftest.py b/tests/conftest.py index 81083d5..ef79c28 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,4 +1,5 @@ import logging +from collections.abc import AsyncGenerator from collections.abc import Generator from pathlib import Path @@ -112,10 +113,12 @@ def tika_client_compressed(tika_host: str) -> Generator[TikaClient, None, None]: @pytest.fixture -async def async_tika_client(tika_host: str) -> AsyncTikaClient: - return AsyncTikaClient(tika_url=tika_host, log_level=logging.INFO) +async def async_tika_client(tika_host: str) -> AsyncGenerator[AsyncTikaClient, None]: + async with AsyncTikaClient(tika_url=tika_host, log_level=logging.INFO) as client: + yield client @pytest.fixture -async def async_tika_client_compressed(tika_host: str) -> AsyncTikaClient: - return AsyncTikaClient(tika_url=tika_host, log_level=logging.INFO, compress=True) +async def async_tika_client_compressed(tika_host: str) -> AsyncGenerator[AsyncTikaClient, None]: + async with AsyncTikaClient(tika_url=tika_host, log_level=logging.INFO, compress=True) as client: + yield client