|
使用unittest.defaultTestLoader.discover(),运行报错:
raise ImportError('Start directory is not importable: %r' % start_dir)
ImportError: Start directory is not importable: 'F:\\python\\selenium_python\\test_case'
代码如下:
- #coding=utf-8
- import unittest
- import HTMLTestRunner
- import os ,time
- from multiprocessing.dummy import Process
- # import sys
- # sys.path.append('\selenium_python')
- list_dir = (r'F:\\python\\selenium_python\\test_case1',r'F:\\python\\selenium_python\\test_case')
- def creatsuitel(start_dir):
- testunit=unittest.TestSuite()
- print 'testunit:',testunit
- #discover 方法定义
- discover=unittest.defaultTestLoader.discover(start_dir,pattern ='start_*.py',top_level_dir=None)
- # print "discover:" ,discover
- #discover 方法筛选出来的用例,循环添加到测试套件中
- for test_suite in discover:
- # print "test_suite:", test_suite
- for test_case in test_suite:
- # print "test_case:", test_case
- testunit.addTests(test_case)
- # print testunit
- return testunit
- # alltestnames = creatsuitel()
- now = time.strftime('%Y-%m-%d-%H_%M_%S',time.localtime(time.time()))
- filename = 'F:\\python\\selenium_python\\report\\'+now+'result.html'
- fp = file(filename, 'wb')
- poclist = []
- for i in range(len(list_dir)):
- print 'list:', list_dir[i]
- runner =HTMLTestRunner.HTMLTestRunner(
- stream=fp,
- title=u'百度搜索测试报告',
- description=u'用例执行情况')
- suite_test = creatsuitel(list_dir[i])
- print 'suite_test:', suite_test
- poc = Process(target=runner.run,args=(suite_test,))
- poclist.append(poc)
- for poc in poclist:
- poc.start()
- for poc in poclist:
- poc.join()
- fp.close()
复制代码 |
|