diff --git a/ldclient/testing/test_aio.py b/ldclient/testing/test_aio.py index 6bf8d8ab..6f75754a 100644 --- a/ldclient/testing/test_aio.py +++ b/ldclient/testing/test_aio.py @@ -6,6 +6,8 @@ """ import asyncio +import subprocess +import sys import threading import time @@ -522,3 +524,23 @@ def test_sse_factory_proxy_precedence(self): assert AsyncSSEFactory(cfg)._proxy == 'http://cfg-proxy:9000' # Neither set -> None (per-URL env fallback happens in create()). assert AsyncSSEFactory(Config('sdk-key'))._proxy is None + + +class TestImportSafety: + def test_import_ldclient_does_not_require_aiohttp(self): + """A bare ``import ldclient`` must not import anything that requires an + optional dependency. aiohttp (the ``async`` extra) is optional, so a + sync-only install must still be able to import ldclient. + """ + code = "import ldclient, sys; sys.exit(1 if 'aiohttp' in sys.modules else 0)" + result = subprocess.run( + [sys.executable, "-c", code], + capture_output=True, + text=True, + ) + + assert result.returncode == 0, ( + "importing ldclient pulled in aiohttp. Keep aiohttp off the eager " + "import path (import async_client / transport lazily).\n" + "stderr:\n%s" % result.stderr + )