【python+unittest 接口自动化测试实战(一)】前置方法:生成随机邮箱、手机号

"""
生成随机邮箱、手机号
"""
# coding=UTF-8
import random
def create_phone():
    # 第二位数字
    second = [3, 4, 5, 7, 8, 9][random.randint(0, 5)]
    # 第三位数字
    third = {
        3: random.randint(0, 9),
        4: [5, 7, 9][random.randint(0, 2)],
        5: [i for i in range(10) if i != 4][random.randint(0, 8)],
        7: [i for i in range(10) if i not in [4, 9]][random.randint(0, 7)],
        8: random.randint(0, 9),
        9: random.randint(0, 9)
    }[second]
    # 最后八位数字
    suffix = random.randint(9999999, 100000000)
    # 拼接手机号
    return "1{}{}{}".format(second, third, suffix)


def create_email():
    first = random_strs(9)
    last = ['qq.com', '126.com', '139.com', '163.com', 'sina.com.cn']
    email = first + '@' + last[random.randint(0, len(last))]
    return email

猜你喜欢

转载自blog.csdn.net/kk_gods/article/details/109053437