代码中的模拟模块由selenium的webdriver运行

时间:2014-07-10 14:40:30

标签: python django selenium mocking

我的代码正在运行一些线程实例。为一些长时间的异步任务执行。

这不允许我使用sqlite后端运行我的django单元测试,因为sqlite无法处理线程中的多个连接。因此,我成功地使用我编写的FakeThread类来模拟Thread(它只是同步运行目标)。

然而,模拟似乎不适用于硒测试。我这样做:

from tests.stubs import FakeThread

# ...
class FunctionalTest(LiveServerTestCase):

    @mock.patch('accounts.models.user_profile.Thread', new=FakeThread)
    def test_register_agency(self):
        self.browser.get("%s%s" % (self.live_server_url, "/register"))
        # .. fill in form, submit, eventually calls something in user_profile
        # using an instance of Thread. Thread seems to still be threading.Thread

知道如何在服务浏览器调用时在selenium运行的代码中模拟Thread吗?谢谢!

0 个答案:

没有答案