Setting liveserver port when running tests in django
If anyone is wondering this is how I did it:Override method setUpClass, which starts the thread on which the server run
@classmethoddef setUpClass(cls): cls.host = "example.com" # or ip cls.port = 12345 super(ExampleTestCase, cls).setUpClass()
All the previous answers work well, but the most succinct way to set the port is as follows:
class MyTestCase(LiveServerTestCase): port = 12345
According to the Django 1.11 release notes you should set the port
attribute on the LiveServerTestCase
:
If you need to bind
LiveServerTestCase
to a specific port, use theport
attribute added in Django 1.11.2.