无法继承正确的父 class,init 采用 1 个位置参数,但给出了 2 个
Cannot inheritance correct parent class, init takes 1 positional argument but 2 were given
我有基地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()
和一个class继承基数的
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')
但我明白了
init() takes 1 positional argument but 2 were given
我如何需要 inerhit 基地 class?
由于您没有在此处覆盖 init() 方法中的任何内容,因此您没有必要将其包含在 StatusesCheckManual subclass.
如果您确实需要覆盖 init(),您也需要在环境中执行此操作,并确保包含相同的参数:
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)
(请注意 super 的第一个参数是当前 class,而不是父级)
我有基地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()
和一个class继承基数的
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')
但我明白了
init() takes 1 positional argument but 2 were given
我如何需要 inerhit 基地 class?
由于您没有在此处覆盖 init() 方法中的任何内容,因此您没有必要将其包含在 StatusesCheckManual subclass.
如果您确实需要覆盖 init(),您也需要在环境中执行此操作,并确保包含相同的参数:
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)
(请注意 super 的第一个参数是当前 class,而不是父级)