diff --git a/src/websockets/asyncio/router.py b/src/websockets/asyncio/router.py index 12b292aa..28c4bf31 100644 --- a/src/websockets/asyncio/router.py +++ b/src/websockets/asyncio/router.py @@ -35,6 +35,10 @@ def unix_route( ) -> Awaitable[Server]: raise ImportError("unix_route() requires werkzeug") + class Router: + def __init__(self, *args: Any, **kwargs: Any) -> None: + raise ImportError("Router() requires werkzeug") + else: class Router: diff --git a/src/websockets/sync/router.py b/src/websockets/sync/router.py index 0292a17d..618b2d55 100644 --- a/src/websockets/sync/router.py +++ b/src/websockets/sync/router.py @@ -35,6 +35,10 @@ def unix_route( ) -> Server: raise ImportError("unix_route() requires werkzeug") + class Router: + def __init__(self, *args: Any, **kwargs: Any) -> None: + raise ImportError("Router() requires werkzeug") + else: class Router: diff --git a/tests/asyncio/test_router.py b/tests/asyncio/test_router.py index 1426cc9f..3dd766c9 100644 --- a/tests/asyncio/test_router.py +++ b/tests/asyncio/test_router.py @@ -186,6 +186,7 @@ async def handler(self, connection): @unittest.skipUnless(hasattr(socket, "AF_UNIX"), "this test requires Unix sockets") +@unittest.skipUnless("werkzeug" in sys.modules, "werkzeug not installed") class UnixRouterTests(EvalShellMixin, unittest.IsolatedAsyncioTestCase): async def test_router_supports_unix_sockets(self): """Router supports Unix sockets.""" diff --git a/tests/sync/test_router.py b/tests/sync/test_router.py index 07274e62..cf04a868 100644 --- a/tests/sync/test_router.py +++ b/tests/sync/test_router.py @@ -162,6 +162,7 @@ def handler(self, connection): @unittest.skipUnless(hasattr(socket, "AF_UNIX"), "this test requires Unix sockets") +@unittest.skipUnless("werkzeug" in sys.modules, "werkzeug not installed") class UnixRouterTests(EvalShellMixin, unittest.IsolatedAsyncioTestCase): def test_router_supports_unix_sockets(self): """Router supports Unix sockets."""