目录结构:
Interface
/common
/datas
/Log
/report
/TestCase
RunTest.py
我的数据源是 yaml 格式,获取 yaml 格式的代码如下:
# -*- coding: UTF-8 -*-
import yaml
import os
class ReadYaml(object):
def __init__(self):
yaml_path = "../datas/TestData.yaml"
with open(yaml_path, "r") as f:
self.content = yaml.load(f)
RunTest.py 代码
# -*- coding:UTF-8 -*-
import os
import unittest
import time
from common import HTMLTestRunner
import sys
reload(sys)
sys.setdefaultencoding("utf-8")
def run_allcase():
try:
test_dir = os.path.join(os.getcwd(), "TestCase")
rep_dir = os.path.join(os.getcwd(), "report/")
new_time = time.strftime("Report%Y-%m-%d.html", time.localtime())
rep_name = rep_dir + new_time
file_open = open(rep_name, "wb")
discover_test = unittest.defaultTestLoader.discover(
test_dir, pattern="test_*.py"
)
runner = HTMLTestRunner.HTMLTestRunner(
stream=file_open, title="Test report", description="用例执行情况:"
)
runner.run(discover_test)
file_open.close()
except Exception as e:
print "running tesecase fail:", e
if __name__ == "__main__":
run_allcase()
运行单个测试文件是成功的(我把路径打印出来是:/Users/imac/Desktop/Interface/datas/TestData.yaml),加入批量执行用例的时候报错提示找不到 yaml 文件,从报错的信息看少了一层 Interface 文件 (我把路径写成绝对路径批量执行是没有问题),包括我把相对路径转换成绝对路径都还是报错。。请问下各位该如何解决呢
IOError: [Errno 2] No such file or directory: '/Users/imac/Desktop/datas/TestData.yaml'