Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions ldclient/testing/test_aio.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"""

import asyncio
import subprocess
import sys
import threading
import time

Expand Down Expand Up @@ -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
)
Loading