Skip to content
Open
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions channels/testing/live.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -69,6 +70,7 @@ def setUpClass(cls):
cls.host,
get_application,
setup=set_database_connection,
port=cls.port,
)
cls._server_process.start()
while True:
Expand Down
6 changes: 6 additions & 0 deletions docs/topics/testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
~~~~~~~~~~~~

Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ tests =
pytest-asyncio
selenium
daphne =
daphne>=4.0.0
daphne>=4.2.1

[options.packages.find]
exclude =
Expand Down
Loading