问题描述
我正在将django用于Web应用程序,并且正在使用docker进行部署.我需要在含硒的容器中进行测试.我正在使用硒网格进行测试.为了与docker上的liveserver连接,我需要将端口转发给特定端口,但是据我在Django文档中所读,LiveServerTestCase使用端口0,这意味着每次我运行测试时都使用随机端口.由于不建议使用--liveserver选项,是否还有其他方法可以设置测试服务器的端口,或者是使用selenium进行测试的更智能的方法?
I am using django for a webapp and I'm using docker to deploy it. I need to test it in the container with selenium. I'm using selenium grid for testing. In order to connect with the liveserver on the docker, i need to port forward a specific port, but as far as i read in the django docs, LiveServerTestCase uses port 0, which means random port every time i run the tests. Since --liveserver options is deprecated, is there any other way to set the port of the test server or a smarter way to test it with selenium ?
提前谢谢!
推荐答案
如果有人想知道我是怎么做到的:覆盖setUpClass方法,该方法启动运行服务器的线程
If anyone is wondering this is how I did it:Override method setUpClass, which starts the thread on which the server run
@classmethod
def setUpClass(cls):
cls.host = "example.com" # or ip
cls.port = 12345
super(ExampleTestCase, cls).setUpClass()
这篇关于在Django中运行测试时设置liveserver端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!