diff --git a/channels/testing/live.py b/channels/testing/live.py index cb2a7c494..87bf9b729 100644 --- a/channels/testing/live.py +++ b/channels/testing/live.py @@ -37,14 +37,15 @@ class ChannelsLiveServerTestCase(TransactionTestCase): ProtocolServerProcess = DaphneProcess static_wrapper = ASGIStaticFilesHandler serve_static = True + port = 0 @property def live_server_url(self): - return "http://%s:%s" % (self.host, self._port) + return "http://%s:%s" % (self.host, self.port) @property def live_server_ws_url(self): - return "ws://%s:%s" % (self.host, self._port) + return "ws://%s:%s" % (self.host, self.port) @classmethod def setUpClass(cls): @@ -69,6 +70,7 @@ def setUpClass(cls): cls.host, get_application, setup=set_database_connection, + port=cls.port, ) cls._server_process.start() while True: diff --git a/docs/topics/testing.rst b/docs/topics/testing.rst index c3547fd85..783a842f1 100644 --- a/docs/topics/testing.rst +++ b/docs/topics/testing.rst @@ -362,6 +362,12 @@ standard Django ``LiveServerTestCase``: }, } +port +~~~~ + +Subclass ``ChannelsLiveServerTestCase`` with ``port = {port_number}`` to bind +both the HTTP and WebSocket servers to a specific port. + serve_static ~~~~~~~~~~~~ diff --git a/setup.cfg b/setup.cfg index 09232fefe..9fb103daf 100644 --- a/setup.cfg +++ b/setup.cfg @@ -44,7 +44,7 @@ tests = pytest-asyncio selenium daphne = - daphne>=4.0.0 + daphne>=4.2.1 [options.packages.find] exclude =