接口自动化测试:测试数据生成的一个小技巧

当我们在生成数据的时候,常用到%d方式进行格式化生成数据。

比如要生成11位的手机号,可以这样:

def test_create_data():
    data = ['138%08d' %x for x in range(20)]
    print(data)

当填充内容不足8位的时候,用0进行填充输出内容:

['13800000000', '13800000001', '13800000002', '13800000003', '13800000004', '13800000005', '13800000006', '13800000007', '13800000008', '13800000009', '13800000010', '13800000011', '13800000012', '13800000013', '13800000014', '13800000015', '13800000016', '13800000017', '13800000018', '13800000019']

详细用法参考博客:https://blog.csdn.net/lijing742180/article/details/80788422

posted @ 2020-10-03 10:34  沧海1024  阅读(601)  评论(0编辑  收藏  举报