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'

代码如下:
  1. #coding=utf-8
  2. import unittest
  3. import HTMLTestRunner
  4. import os ,time
  5. from multiprocessing.dummy import Process
  6. # import sys
  7. # sys.path.append('\selenium_python')

  8. list_dir = (r'F:\\python\\selenium_python\\test_case1',r'F:\\python\\selenium_python\\test_case')

  9. def creatsuitel(start_dir):
  10.     testunit=unittest.TestSuite()
  11.     print 'testunit:',testunit
  12.     #discover 方法定义
  13.     discover=unittest.defaultTestLoader.discover(start_dir,pattern ='start_*.py',top_level_dir=None)
  14. #     print "discover:" ,discover
  15.     #discover 方法筛选出来的用例,循环添加到测试套件中
  16.     for test_suite in discover:
  17. #         print "test_suite:", test_suite
  18.         for test_case in test_suite:
  19. #             print "test_case:", test_case
  20.             testunit.addTests(test_case)
  21. #             print testunit
  22.     return testunit
  23. # alltestnames = creatsuitel()
  24. now = time.strftime('%Y-%m-%d-%H_%M_%S',time.localtime(time.time()))
  25. filename = 'F:\\python\\selenium_python\\report\\'+now+'result.html'
  26. fp = file(filename, 'wb')
  27. poclist = []
  28. for i in range(len(list_dir)):
  29.     print 'list:', list_dir[i]
  30.     runner =HTMLTestRunner.HTMLTestRunner(
  31.     stream=fp,
  32.     title=u'百度搜索测试报告',
  33.     description=u'用例执行情况')
  34.     suite_test = creatsuitel(list_dir[i])
  35.     print 'suite_test:', suite_test
  36.     poc = Process(target=runner.run,args=(suite_test,))
  37.     poclist.append(poc)
  38. for poc in poclist:
  39.     poc.start()
  40. for poc in poclist:
  41.     poc.join()

  42. fp.close()
复制代码





欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2