51Testing软件测试论坛
标题:
unittest.defaultTestLoader.discover()报错,求助!!!
[打印本页]
作者:
余寒12
时间:
2016-5-10 18:45
标题:
unittest.defaultTestLoader.discover()报错,求助!!!
使用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()
复制代码
欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/)
Powered by Discuz! X3.2