python-造数据

测试数据不知道怎么造?看这里

“”"
一、造数据
1,安装faker
pip install Faker
2、常用数据
四要素
1,姓名
name = fk.name()
2,身份证
id_card = fk.ssn()
3,手机号
phone = fk.phone_number()
4,银行卡
card = fk.credit_card_number()
个人信息
1,地址
addr = fk.address()
2,邮箱
email = fk.email()
3,公司
company = fk.company()
4,公司邮箱
company_email = fk.company_email()
5,工作岗位
job = fk.job()
6,更多的个人信息

per = fk.profile()

7,简单的个人信息
per = fk.simple_profile()
随机数
res=fk.random_int(min=100,max=999)
文本
1,生成一句话
res = fk.sentence()
2,生成一段文字
text = fk.text()
3,随机生成字符串
test_str = fk.pystr()
时间
一、不指定时间范围
1,不指定时间从1970年开始
2,年
year = fk.year()
3,当年年
this_year = fk.date_this_year()
4,月
month = fk.month()
5,当前月:
this_month = fk.date_this_month()
6,精确到秒
date_time=fk.date_time()
7,年月日
date_time = fk.date()
二、指定时间
1,年月日
target__time = fk.date_between(start_date="-3y",end_date="-1y")
-1y:一年前
-1m:一个月前
today:今天
2,精确到秒
target__time_now = fk.date_time_between(start_date="-2y",end_date=“now”)
-1y:一年前
-1m:一个月前
now:此刻
三、未来时间
future_date = fk.future_date()

print(future_date)

future_date_time = fk.future_datetime()
print(future_date_time)
“”"

from faker import Faker

fk = Faker(locale=“zh-CN”)

#姓名
name = fk.name()
print(name)

#身份证
id_card = fk.ssn()
print(id_card)
#手机号
phone = fk.phone_number()
print(phone)
#银行卡
card = fk.credit_card_number()
print(card)
#地址
addr = fk.address()
print(addr)

#邮箱
email = fk.email()
print(email)

#公司
company = fk.company()
print(company)

#公司邮箱
company_email = fk.company_email()
print(company_email)

#工作岗位
job = fk.job()
print(job)
#个人信息

per = fk.profile()

per = fk.simple_profile()
print(per)
#随机数
res=fk.random_int(min=100,max=999)
print(res)
#生成一句话
res = fk.sentence()
print(res)
#生成一段文字
text = fk.text()
print(text)
#随机生成字符串
test_str = fk.pystr()
print(test_str)

#生成多个数据,保证数据不重复
result =[fk.unique.name() for i in range(10)]
print(result)
#年
year = fk.year()
this_year = fk.date_this_year()

print(this_year)

#月
month = fk.month()
this_month = fk.date_this_month()

print(this_month)

#精确到秒
date_time=fk.date_time()

print(date_time)

#年月日
date_time = fk.date()

print(date_time)

#指定时间范围 年月日
target__time = fk.date_between(start_date="-3y",end_date=“today”)
print(target__time)
#指定时间范围 年月日 时分秒
target__time_now = fk.date_time_between(start_date="-2y",end_date=“now”)
print(target__time_now)
#未来时间
future_date = fk.future_date()

print(future_date)

future_date_time = fk.future_datetime()
print(future_date_time)

#数据共享,通过类方法Faker.seed(123)实现
class TestDemo:
def init(self):
self.fk = Faker(locale=“zh-CN”)
def test_01(self):
Faker.seed(123) #数字一样名字一样
print(self.fk.name())
def test_02(self):
Faker.seed(124) #数字不一样名字不一样
print(self.fk.name())
if name == ‘main’:
cl = TestDemo()
cl.test_01()
cl.test_02()

更多数据,请看下面文章
http://testingpai.com/article/1615615023407

  • 0
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值