@pytest.mark.parametrize("name_old, name_new", [
("wangmu", 'haha'),
("zhangsan", 'seveniruby')
])
def test_all(self, name_old, name_new):
data = self.tag.get()
for name in [name_old, name_new]:
tag_id = self.tag.jsonpath(data, f'$..tag[?(@.name=="{name}")].id')
if tag_id:
print(name)
self.tag.delete(tag_id[0])
assert self.tag.add(name_old)['errcode'] == 0
tag_id = self.tag.jsonpath(self.tag.get(), f'$..tag[?(@.name=="{name_old}")].id')[0]
assert self.tag.update(tag_id, name_new)['errcode'] == 0
yaml数据
测试数据的数据驱动
class TestTag:
tag = Tag()
test_data = tag.load('test_tag.data.yaml')
@classmethod
def setup_class(cls):
pass
def setup(self):
pass
@pytest.mark.parametrize("name_old, name_new", test_data)
数据驱动
@classmethod
def template(cls, path, data, sub=None):
with open(path, 'r') as f:
if sub is None:
return yaml.load(Template(f.read()).substitute(data))
else:
return yaml.load(
Template(
yaml.dump(
yaml.load(f)[sub])).substitute(data))