我尝试使用ThreadPoolExecutor以并行模式运行测试,这是我的Runner类
suite = unittest.TestSuite()
if (options == 'by_method'):
for object in name:
for method in dir(object):
if (method.startswith('test')):
suite.addTest(object(method))
with ThreadPoolExecutor(max_workers=devicesList.__len__()) as executor:
list_of_suites = list(suite)
for test in range(len(list_of_suites)):
test_name = str(list_of_suites[test])
try:
executor.submit(unittest.TextTestRunner(verbosity=2).run, list_of_suites[test])
except:
pass
这是我的测试课
import unittest
class Runner(unittest.TestCase):
@classmethod
def setUpClass(self):
print("setup method")
def test_deeplinks(self):
print("test1")
def test(self):
print("test2");
def test4(self):
print("test 4")
def test5(self):
print("test5");
@classmethod
def tearDownClass(self):
print("tear down ")
if __name__ == '__main__':
# runner = Runner.Runner()
# runner.parallel_execution(Runner, TestDeeplinks)
suite = unittest.TestLoader().loadTestsFromTestCase(Runner)
unittest.TextTestRunner(verbosity=2).run
但是我的setupClass方法没有被调用有人能告诉我我在这里做什么吗
1条答案
按热度按时间erhoui1w1#
也许您需要使用
setUp()
而不是setUpClass()
setUpClass()
在整个类中仅运行一次https://stackoverflow.com/a/23670844/6243764