Search code examples
pythonseleniumclassinitbase-class

Cannot inheritance correct parent class, init takes 1 positional argument but 2 were given


I have a base class

class Environment(unittest.TestCase):
    def setUp(self):
        options_for_console_log = DesiredCapabilities.CHROME
        options_for_console_log['loggingPrefs'] = {'browser': 'ALL'}
        self.driver = webdriver.Chrome(desired_capabilities=options_for_console_log)
        self.driver.maximize_window()
        print('1', self.driver)

    def tearDown(self):
        driver = self.driver
        driver.close()

and a class what inherit base one

class StatusesCheckManual(Environment):
    def __init__(self):
        super(Environment).__init__()

    def test_1_add_materials(self):

        self.create_order = CreateOrder(self.driver)
        self.order_statuses = Order_manual_statuses(self.driver)
        self.order = Order(self.driver)


        self.order_id = self.create_order.create_fake_order()

        LoginAsAdmin(self.driver).login()

        self.order.go_to_order(self.order_id)
        status = self.order_statuses.change_to_addmat()
        self.assertEqual(status, 'Add Materials')

but i get

init() takes 1 positional argument but 2 were given

How do i need to inerhit base class?


Solution

  • since you are not overriding anything in the init() method here, it is unnecessary for you to include it in your StatusesCheckManual subclass.

    If you do need to override init(), you'll need to do it in Environment as well, and be sure to include the same args:

    class StatusesCheckManual(Environment):
        def __init__(self, methodName='runTest'):
            super(StatusesCheckManual, self).__init__(methodName)
    
    class Environment(unittest.TestCase):
        def __init__(self, methodName='runTest'):
            super(Environment, self).__init__(methodName)
    

    (please note the the first arg for super is the current class, not the parent)