我以这种方式解决了问题(使用了 phantom-js 而不是 HTMLUNIT ,因为它是唯一剩余的稳定版本的代码)。
from django.test import LiveServerTestCasefrom selenium import webdriverfrom os import environclass SeleniumTestCase(LiveServerTestCase): __test__ = False @classmethod def setUpClass(cls): environ['NO_PROXY'] = '127.0.0.1' # The key point cls.selenium = webdriver.PhantomJS(service_args=['--proxy-type=none']) super(SeleniumTestCase, cls).setUpClass() @classmethod def tearDownClass(cls): cls.selenium.close() cls.selenium.quit() super(SeleniumTestCase, cls).tearDownClass()class TestFoo(SeleniumTestCase): def setUp(self): # do something before every test method runs pass def test_foo(self): # test pass



