When automated tests often occur, we need to prepare their own test data. To ensure the reuse use cases, we need strict:
(1) Method 1
random random number
time time
For example:
print time.strftime("%H%M%S",time.localtime())
"% H% M% S" are free to become Kazakhstan, if desired email address could write
print time.strftime ( "test%H%M%[email protected]", time.localtime ()) which is to automate the testing process common
(2) Second way
third-party libraries for python testdata
direct pip install testdata
View whether the installation is complete pip show testdataprint testdata.get_ascii () Gets asc you can specify the length
print testdata.get_md5 (val = 'test' ) acquires MD5
value
print testdata.get_email (name = 'dfd' ) obtaining In Email
Print testdata.get_hash () Gets a hash value, there are many
ways three
third-party libraries faker python is
directly performed pip installation pip install faker
see if the installation is complete pip show faker
Import Faker faker from
Fake = Faker ( "zh_CN") can Region
from faker.providers import internet
Get name print fake.name ()
# for i in range(10):
# print fake.name()
fake.add_provider(internet)
print fake.ipv4() ip地址
print fake.text() 获取文本
指定文本
list=['test1','test2','test3']
print fake.sentence(ext_word_list=list)
print fake.random.getstate
for i in range(10):
print fake.email() 获取email