相关疑难解决方法(0)

当我运行多个测试时,Django LiveServerTestCase无法加载页面

我正在尝试在一个Django LiveServerTestCase中运行多个测试。当我运行任何单个测试(并带有其他评论)时,一切都会按预期进行。但是,当我用两个测试运行测试用例时,第一个工作正常,但第二个加载页面时显示“内部服务器错误”消息。

码:

from django.test import LiveServerTestCase
from selenium.webdriver.firefox.webdriver import WebDriver


class MyLiveServerTestCase(LiveServerTestCase):    
    """
    BaseCleass for my selenium test cases
    """
    @classmethod
    def setUpClass(cls):
        cls.driver = WebDriver()
        cls.url = cls.live_server_url    

        super(MyLiveServerTestCase, cls).setUpClass()

    @classmethod
    def tearDownClass(cls):
        cls.driver.quit()
        super(MyLiveServerTestCase, cls).tearDownClass()

class AdminEditFormTest(MyLiveServerTestCase):
    """
    Some test case
    """

    def test_valid_data(self):
        """
        test when user enters correct data
        """
        self.driver.get(self.url)
        # ...

    def test_invalid_data(self):
        """ test when user enters INcorrect data """
        self.driver.get(self.url)
        # ...
Run Code Online (Sandbox Code Playgroud)

如果我使用它close()而不是quit()它,则会失败,并显示“错误98:地址已在使用中”,类似于情况,除了仅当我在一个LiveServerTestCase类中具有多个测试或在一个.py文件中具有多个测试用例时才出现错误。

如何在tearDown上使LiveServerTestCase空闲端口(如果这是核心问题)?

有什么解决方法吗?我想要的只是功能性的硒测试,它们在本地和远程服务器上均能运行。 …

python django selenium selenium-webdriver

5
推荐指数
1
解决办法
1344
查看次数

标签 统计

django ×1

python ×1

selenium ×1

selenium-webdriver ×1