mock主要作用是在测试用例过程中,快速生成数据,如时间,字符串,数字,等,也集成了faker。
集成了faker
class MockData:
"""
创建随机数据。
"""
def __init__(self):
self.form_maps = {
"default_form": "%Y-%m-%d %H:%M:%S",
"connect_form": "%Y%m%d%H%M%S",
"day_form": "%Y-%m-%d",
"hour_form": "%H:%M:%S",
"TZ_form": "%Y-%m-%dT%H:%M:%S.%fZ"
}
self.time_form = "%Y-%m-%d %H:%M:%S" # 时间输出默认格式
self.fake = faker.Faker("zh_CN")
使用时的:
def test_1010(self):
"""示例"""
self.tci["验证点"] = "用例示例"
...
my_stock_info["cause"] = self.mocker.fake.word()
def test_1005(self):
self.tci["验证点"] = "调整时间搜最近30天"
...
start_time = self.mocker.diff_from_now("day", -30)
end_time = self.mocker.now("day_form")
self.tci["参数"] = {
"endTime": end_time,
"startTime": start_time,
"scope": 1
}