使用Python第1章的TDD没有来自functional_tests.py的输出

时间:2015-07-08 21:38:52

标签: python django selenium

我正在使用Python阅读TDD一书。在第1章中有一段代码

from selenium import webdriver
import unittest

class NewVisitorTest(unittest.TestCase): 

    def setUp(self): 
        self.browser = webdriver.Firefox()
        self.browser.implicitly_wait(5)

    def tearDown(self): 
        self.browser.quit()

    def test_can_start_a_list_and_retrieve_it_later(self): 
        self.browser.get('http://localhost:8000')
        self.assertIn('To-Do', self.browser.title)  
        self.fail('Finish the test!')

if __name__ == '__main__':
    unittest.main(warnings='ignore')

该文件名为functional_tests.py。我在Ubuntu 14.04上全局安装了django 1.7和selenium。我也开始了新的项目超级名单。我在尝试测试之前运行服务器。当我用

运行测试时
 python3 functional_tests.py

Firefox窗口打开并加载默认的Django启动页面,即使在测试运行后它应该关闭,窗口也会保持打开状态。此外,测试根本没有输出。我期待这样的事情:

F
======================================================================
FAIL: test_can_start_a_list_and_retrieve_it_later (__main__.NewVisitorTest)
 ---------------------------------------------------------------------
Traceback (most recent call last):
 File "functional_tests.py", line 18, in
test_can_start_a_list_and_retrieve_it_later
    self.assertIn('To-Do', self.browser.title)
AssertionError: 'To-Do' not found in 'Welcome to Django'

 ---------------------------------------------------------------------
Ran 1 test in 1.747s

FAILED (failures=1)

可能是什么问题?感谢

1 个答案:

答案 0 :(得分:0)

您安装了最新版本的Selenium吗?正如书中所提到的,你应该有匹配版本的Firefox和Selenium。