Python selenium tests for django throw Address already in use at setUpClass

2024-09-27 17:58:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我要为我的django项目做硒测试。硒测试的基类有以下方法:

from django.test import TestCase, LiveServerTestCase

from selenium import webdriver
from pyvirtualdisplay import Display

class BaseTestCase(TestCase):

    def setUp(self):
        self.aux_model = models.Sample.objects.create(name='test', value=123)

    def tearDown(self):
        self.aux_model.delete()

class BaseSeleniumTestCase(BaseTestCase, LiveServerTestCase):

    @classmethod
    def setUpClass(cls):
        cls.display = Display(visible=0, size=(1024, 768))
        cls.display.start()
        cls.driver = webdriver.Firefox()
        cls.driver.implicitly_wait(15)
        cls.driver.set_page_load_timeout(30)
        super(BaseSeleniumTestCase, cls).setUpClass()

    @classmethod
    def tearDownClass(cls):
        cls.driver.quit()
        cls.display.stop()
        super(BaseSeleniumTestCase, cls).tearDownClass()

我在ubuntu14.04服务器virtualbox上运行测试。我经常得到一个失败的测试,这与任何特定的测试无关

^{pr2}$

只有在运行硒测试时才会发生这种情况。在

我使用选项--liveserver运行测试=本地主机:9000-9300在

我使用django1.6.1和python2.7.6

我如何调查这个问题的根本原因?在


Tags: djangofromtestimportselfdefdriverdisplay

热门问题