[patch] Fix optional dependency handling for Redis and MinIO adapters #19

Merged
brian merged 4 commits from cursor/fix-optional-dependencies into main 2026-06-30 16:08:03 +02:00
Showing only changes of commit f5953906c1 - Show all commits
+19 -2
View File
@@ -4,15 +4,19 @@ from __future__ import annotations
import builtins
import importlib
import os
import subprocess
import sys
from collections.abc import Callable, Mapping, Sequence
from pathlib import Path
from types import ModuleType
from unittest.mock import patch
import pytest
import python_repositories
from python_repositories import JsonRepositoryInterface
_ROOT = Path(__file__).resolve().parents[2]
def _block_backend_import(blocked_prefix: str) -> Callable[..., ModuleType]:
@@ -33,10 +37,23 @@ def _block_backend_import(blocked_prefix: str) -> Callable[..., ModuleType]:
def test_base_import_does_not_load_adapters() -> None:
"""Interfaces are available without loading adapter modules."""
"""Base package import does not eagerly load backend adapter modules."""
script = """
import sys
from python_repositories import JsonRepositoryInterface
assert JsonRepositoryInterface is not None
assert "python_repositories.adapters.redis_adapter" not in sys.modules
assert "python_repositories.adapters.minio_adapter" not in sys.modules
"""
result = subprocess.run(
[sys.executable, "-c", script],
cwd=_ROOT,
env={**os.environ, "PYTHONPATH": str(_ROOT)},
capture_output=True,
text=True,
)
assert result.returncode == 0, result.stderr or result.stdout
def test_lazy_adapter_load_succeeds_when_extra_present() -> None: