继承
class Animal(object):
def run(self):
print(‘Animal is running...‘)
class Dog(Animal):
pass
class Cat(Animal):
pass
Dog().run()
Cat().run()
运行结果:
Animal is running...
An animal is running...
多态(重写)
class Animal(object):
def run(self):
print(‘Animal is running...‘)
class Dog(Animal):
def run(self):
print(‘Dog is running...‘)
class Cat(Animal):
def run(self):
print(‘Cat is running...‘)
Dog().run()
Cat().run()
运行结果:
Dog is running...
Cat is running...
多继承
import unittest
from selenium import webdriver
class MyTest(unittest.TestCase):
def setUp(self):
print("=============开始执行测试=============")
self.driver=webdriver.Chrome()
self.driver.get(‘https://www.baidu.com‘)
self.driver.implicitly_wait(5)
self.driver.maximize_window()
def tearDown(self):
self.driver.quit()
print("=============结束执行测试=============")
class A(object):
def getName(self):
print("name is A")
class C(MyTest,unittest.TestCase):
def test_name(self):
print("name is C")
class D(C,unittest.TestCase):
def test_home(self):
print("name is D")
unittest.main()
运行结果:
=============开始执行测试=============
name is C
.=============结束执行测试=============
=============开始执行测试=============
name is D
.=============结束执行测试=============
=============开始执行测试=============
name is C
.
=============结束执行测试=============
原文:https://www.cnblogs.com/hghua/p/13398298.html