Trình tạo dữ liệu Faker
Tạo dữ liệu mô phỏng thực tế một cách dễ dàng.
Tổng quan
Faker xử lý việc mô phỏng dữ liệu theo thuật toán và miền địa phương cụ thể một cách nhanh chóng.
Nó cho phép cấu hình kiểm tra CI liền mạch.
Đầu ra mã & thực thi
Tạo bản đồ hồ sơ mô phỏng người dùng duy nhất bằng cách sử dụng hạt giống.
faker_demo.py
Thử trong Trình chỉnh sửafrom faker import Faker
import json
# Initialize faker
fake = Faker()
# Set seed for reproducibility
Faker.seed(42)
def generate_users(count=3):
users = []
for _ in range(count):
profile = mock_profile()
users.append(profile)
return users
def mock_profile():
return {
"id": fake.uuid4()[:8],
"name": fake.name(),
"job": fake.job(),
"address": fake.address().replace('\n', ', '),
"email": fake.company_email(),
"ip": fake.ipv4()
}
mock_data = generate_users(3)
print(json.dumps(mock_data, indent=2))Đầu ra thiết bị đầu cuối
[
{
"id": "270dbde2",
"name": "Allison Hill",
"job": "Buyer, industrial",
"address": "Unit 2011 Box 5691, DPO AP 03681",
"email": "shannon41@gonzales.com",
"ip": "20.245.106.63"
}, ...
]Triển khai từng bước
- Gieo cơ sở dữ liệu
- Bộ thử nghiệm đơn vị
- Đảm bảo chất lượng tự động