start_run.py 文件
#coding=utf-8
import os,time

k=1
while k<2:
now_time=time.strftime('%H_%M')
if now_time=="10_52":
print('开始运行脚本:')
os.chdir('C:\Users\340088\PycharmProjects\mail126_project')
os.system('python all_test.py')
print('运行完毕')
break
else:
time.sleep(10)
print(now_time)

报错:开始运行脚本:
Traceback (most recent call last):
File "all_test.py", line 3, in
import HTMLTestRunner
ImportError: No module named 'HTMLTestRunner'
运行完毕

all_test.py 文件:
#coding=utf-8
import unittest,time
import HTMLTestRunner

def creatsuite():
testunit=unittest.TestSuite()
test_dir='C:\Users\340088\PycharmProjects\mail126_project\test_case'

discover=unittest.defaultTestLoader.discover(test_dir,pattern ='test*.py',top_level_dir=None)

for test_suite in discover:
for test_case in test_suite:
testunit.addTests(test_case)
print(testunit)
return testunit
now=time.strftime("%Y-%m-%d %H_%M_%S")
filename="C:\Users\340088\PycharmProjects\mail126_project\report\"+now+"result.html"
fp=open(filename,"wb")
runner=HTMLTestRunner.HTMLTestRunner(stream=fp,title=u"126 邮箱测试报告",description=u"测试用例执行情况")

if name=='main':
all_case=creatsuite()
runner.run(all_case)
fp.close()

我单独运行 all_test.py 的时候能正常运行,但运行 start_run.py 的时候报错


↙↙↙阅读原文可查看相关链接,并与作者交流