python 的 TDD,意外的单元测试错误

TDD with python, unexpected unittest error

这是我的代码;

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_list_and_retrieve_later(self):
    # checkout the homepage
        self.browser.get('http://127.0.0.1:8000')

    # check title and header
        self.assertIn('To-Do', self.browser.title)
        self.fail('Finish the test')

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

导致以下错误:

$ python3 functional_tests.py 
E
======================================================================
ERROR: test_can_start_list_and_retrieve_later         (__main__.NewVisitorTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "functional_tests.py", line 15, in     test_can_start_list_and_retrieve_later
self.browser.get('http://127.0.0.1:8000')
AttributeError: 'NewVisitorTest' object has no attribute 'browser'

----------------------------------------------------------------------
Ran 1 test in 0.000s

FAILED (errors=1)

代码取自 TDD python

我的代码与教程中编写的代码相匹配,但应该会产生 assertIn 错误,因为页面尚未设置。任何帮助将不胜感激。

有错别字:setup应该是setUp. And teardown should be tearDown

class NewVisitorTest(unittest.TestCase):

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

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

    ...