Manuals / Playwright with Python / Chapter 23
Part 3 · Test Structure & Framework · intermediate · ~40 min · Chapter 23 of 61
16. Test Data Management
Static fixtures (JSON/CSV/YAML) For predictable, reusable test data, store it in a file rather than hardcoding it inline across tests. json // test_data/users.json { "valid_user": {"username": "testuser", "password": "testpass"}, "invalid_user": {"username": "baduser", "password": "wrongpass"} } python import json @pytest.fixture def user_data(): with open("test_data/users.json") as f: return json
Step 1 of 3
Overview
Static fixtures (JSON/CSV/YAML) For predictable, reusable test data, store it in a file rather than hardcoding it inline across tests. json // test_data/users.json { "valid_user": {"username": "testuser", "password": "testpass"}, "invalid_user": {"username": "baduser", "password": "wrongpass"} } python creds = user_data["valid_user"] What it does: Parses a JSON file into a Python dictionary/list. Types/params: Pointers: Keep test data files separate from test logic — this lets non-engineers (or future you) update test data without touching test code, and keeps large data sets from cluttering test files. Using faker for dynamic data For tests needing unique data every run (signup flows that reject duplicate emails, for example), generate realistic fake data on the fly instead of relying on static fixtures. python fake = Faker() "email": fake.email(), "name": fake.name(), "phone": fake.phone_number(),
Chapter learning outcomes
- Overview (2)
Clear these before you leave
Side quest
16. Test Data Management deliverable
Apply one idea from “Overview” in a small script or note.