fix(webui): package-qualify webui_testclient import across test suite (Closes #682)
This commit is contained in:
@@ -9,7 +9,6 @@ import warnings
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
||||
|
||||
|
||||
class TestHttpx2Installed(unittest.TestCase):
|
||||
@@ -21,32 +20,39 @@ class TestHttpx2Installed(unittest.TestCase):
|
||||
class TestNoStarletteTestClientDeprecation(unittest.TestCase):
|
||||
def test_starlette_testclient_import_does_not_warn(self) -> None:
|
||||
# Force a fresh import path so a previous httpx-fallback warning cannot
|
||||
# hide a regression after httpx2 is present.
|
||||
for name in list(sys.modules):
|
||||
if name == "starlette.testclient" or name.startswith("starlette.testclient."):
|
||||
# hide a regression after httpx2 is present. Restore sys.modules afterwards.
|
||||
saved = {
|
||||
name: sys.modules[name]
|
||||
for name in list(sys.modules)
|
||||
if name == "starlette.testclient" or name.startswith("starlette.testclient.")
|
||||
}
|
||||
try:
|
||||
for name in list(saved):
|
||||
del sys.modules[name]
|
||||
|
||||
with warnings.catch_warnings(record=True) as caught:
|
||||
warnings.simplefilter("always")
|
||||
import starlette.testclient as testclient # noqa: F401
|
||||
with warnings.catch_warnings(record=True) as caught:
|
||||
warnings.simplefilter("always")
|
||||
import starlette.testclient as testclient # noqa: F401
|
||||
|
||||
dep = [
|
||||
w
|
||||
for w in caught
|
||||
if "httpx" in str(w.message).lower()
|
||||
and "deprecated" in str(w.message).lower()
|
||||
]
|
||||
self.assertEqual(
|
||||
dep,
|
||||
[],
|
||||
f"expected no Starlette httpx deprecation warning; got: "
|
||||
f"{[str(w.message) for w in dep]}",
|
||||
)
|
||||
dep = [
|
||||
w
|
||||
for w in caught
|
||||
if "httpx" in str(w.message).lower()
|
||||
and "deprecated" in str(w.message).lower()
|
||||
]
|
||||
self.assertEqual(
|
||||
dep,
|
||||
[],
|
||||
f"expected no Starlette httpx deprecation warning; got: "
|
||||
f"{[str(w.message) for w in dep]}",
|
||||
)
|
||||
finally:
|
||||
sys.modules.update(saved)
|
||||
|
||||
def test_canonical_webui_testclient_import(self) -> None:
|
||||
with warnings.catch_warnings(record=True) as caught:
|
||||
warnings.simplefilter("always")
|
||||
from webui_testclient import TestClient
|
||||
from tests.webui_testclient import TestClient
|
||||
from webui.app import create_app
|
||||
|
||||
client = TestClient(create_app())
|
||||
|
||||
Reference in New Issue
Block a user