Fix optional-deps import test for full-suite execution.
Run the base-import assertion in a subprocess so integration tests do not pollute sys.modules. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
co-authored by
Cursor
parent
1f02195c27
commit
f5953906c1
@@ -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."""
|
||||
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
|
||||
"""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:
|
||||
|
||||
Reference in New Issue
Block a user