Attribute error in python unittest
Question: On executing this unittest getting

AttributeError: 'BaseUnit' object has no attribute 'driver'

    
    
    import unittest
    import redis
    from selenium import webdriver
    redis = redis.Redis(host='abc', port='123')
    keys = redis.keys('*')
    raw_baseunit = redis.get('test:baseunit')`enter code here`
    
    class BaseUnit(unittest.TestCase):
            def setup(self):
                    self.driver = webdriver.PhantomJS()
    
            def test(self):
                    self.driver.get("myurl")
                    self.driver.find_element_by_id('username').send_keys("ngeo_pur1")
                    self.driver.find_element_by_id('password').send_keys("anything")
                    self.driver.find_element_by_xpath('html/body/div[1]/div[3]/div/section/div/form/ul/li[5]/div[2]/div/input').click()
                    self.driver.get("url")
                    self.driver.find_element_by_partial_link_text("18757424").click()
                    self.driver.find_element_by_xpath(".//*[@id='tabs']/nav/ul/li[2]/a/i").click()
                    Actual = self.driver.find_element_by_xpath(".//*[@id='subcat_baseModelSection.baseModelChoice']/div/div[1]").text
    
                    keys = redis.keys('*')
                    raw_baseunit = redis.get('test:baseUnit')
                    print "Actual Base Unit=",Actual
                    print "Expected Base Unit=",raw_baseunit
                    self.assetEquals(raw_baseunit,Actual)
    
            def teardown(self):
                    self.driver.quit()
    
    if __name__ == '__main__':
        unittest.main()
    

Tried changing the class name 'BaseUnit' as well


Answer: The methods you want to override in
[`unittest.TestCase`](https://docs.python.org/2/library/unittest.html#unittest.TestCase)
are `setUp` and `tearDown` (note the capital "U" and "D"), not `setup` and
`teardown`.

Your all-lowercase `setup` method doesn't called before the test methods run
(if it gets called at all), so the `self.driver` attribute doesn't exist when
then `test` method tries to use it.

