因此,我的方法是设置一个基本测试,其中包含设备必须通过的所有测试。你可以从他们的设备中继承特定的设备。在# this is the base test. Everything that is not specific to the device is set up here. It also contains all the testCases.
import unittest
class deviceTest( unittest.TestCase ):
def setUp( self ):
'''
General setUp here
'''
self.desired_caps = {}
self.desired_caps['key2'] = 'constant value'
def testWorkflow( self ):
'''
Here come the tests that the devices have to pass
'''
class device1Test( deviceTest ):
def setUp( self ):
'''
device1 specific setup
'''
#also run general setUp
deviceTest.setUp( self )
self.desired_caps['key1'] = device
self.driver = webdriver.Remote(url, desired_caps)
class device2Test( deviceTest ):
def setUp( self ):
'''
device2 specific setup
'''
#also run general setUp
deviceTest.setUp( self )
self.desired_caps['key1'] = device
self.driver = webdriver.Remote(url, desired_caps)
if __name__ == '__main__':
suite = unittest.defaultTestLoader.loadTestsFromTestCase( device1Test )
suite.addTest( unittest.defaultTestLoader.loadTestsFromTestCase(device2Test ) )
unittest.TextTestRunner( verbosity = 2 ).run( suite )