Manuals / Playwright with Python / Chapter 22
Part 3 · Test Structure & Framework · intermediate · ~40 min · Chapter 22 of 61
15. Configuration Management
pytest.ini / conftest.py as config equivalent Since Python Playwright has no built-in config file (unlike the JS test runner's playwright.config.ts), pytest.ini fills that role for pytest-level settings, and conftest.py handles anything needing actual code (like environment-based fixture values). ini # pytest.ini [pytest] markers = smoke: quick critical-path tests regression: full regression suite
Step 1 of 2
Overview
Since Python Playwright has no built-in config file (unlike the JS test runner's playwright.config.ts), pytest.ini fills that role for pytest-level settings, and conftest.py handles anything needing actual code (like environment-based fixture values). ini [pytest] markers = smoke: quick critical-path tests regression: full regression suite addopts = --headed --browser chromium What it does: Central place for pytest-level settings: registered markers, default command-line options, test discovery rules. Types/params: Pointers: Registering markers here (Chapter 13) is what keeps @pytest.mark.smoke from producing warnings and documents what each marker means for the rest of the team. Environment variables, base URLs python bash BASE_URL=https://prod.example.com pytest What it does: Reads an environment variable, falling back to a default if it isn't set. Types/params: Pointers: This is the standard pattern for making a test suite environment-aware without hardcoding URLs, so the exact same test code runs against dev, staging, or prod depending on how it's invoked. Managing multiple environments (dev/staging/prod) A common pattern is separate .env-style files or a small config dictionary keyed by environment name: python
- markers — list of name: description pairs, required to avoid "unknown marker" warnings
- addopts — string of default CLI flags applied to every pytest run automatically
- key (string, required) — the environment variable name
- default (any, optional) — the value to return if the variable isn't set
Try it
Run / study this snippet
# conftest.pyChapter learning outcomes
- ENVIRONMENTS = {
Clear these before you leave
Side quest
15. Configuration Management deliverable
Apply one idea from “Overview” in a small script or note.