How microsoft/playwright-pytest works
This repository provides synchronous and asyncio pytest plugins that turn test functions into Playwright browser sessions and fixtures. The principal workflow is test suite → plugin fixtures and browser/context setup → browser interaction; the plugins also expose base-URL configuration, browser selection, debugging, and failure artifacts such as traces, screenshots, and video. Artifact recording is a useful internal layer in each plugin. The sampled excerpts show fixture and recorder behavior, but not every fixture or hook, so some documented capabilities have no detailed internal edges.
Main entry points: pytest_playwright/pytest_playwright.py Sync fixtures · pytest_playwright_asyncio/pytest_playwright.py Async fixtures · pytest_playwright/_base_url_fallback.py Base URL fallback · pytest_playwright_asyncio/_base_url_fallback.py Base URL fallback
Components 11
Synchronous plugin
- Sync fixtures
pytest-playwright/pytest_playwright/pytest_playwright.py - Base URL fallback
pytest-playwright/pytest_playwright/_base_url_fallback.py
Async plugin
- Async fixtures
pytest-playwright-asyncio/pytest_playwright_asyncio/pytest_playwright.py - Base URL fallback
pytest-playwright-asyncio/pytest_playwright_asyncio/_base_url_fallback.py
Artifact capture
- Sync artifact recorder
pytest-playwright/pytest_playwright/pytest_playwright.py - Async artifact recorder
pytest-playwright-asyncio/pytest_playwright_asyncio/pytest_playwright.py
Other components
- Test suite
- pytest runner
- Playwright runtime
- Browser engines
- Artifact files
Connections 13
- Test suite → pytest runner: runs tests
README.md - pytest runner → Sync fixtures: loads plugin
- pytest runner → Async fixtures: loads plugin
- Sync fixtures → Playwright runtime: starts runtime
pytest-playwright/pytest_playwright/pytest_playwright.py - Async fixtures → Playwright runtime: starts runtime
- Sync fixtures → Browser engines: launches browser
pytest-playwright/pytest_playwright/pytest_playwright.py - Async fixtures → Browser engines: launches browser
pytest-playwright-asyncio/pytest_playwright_asyncio/pytest_playwright.py - Sync fixtures → Base URL fallback: uses fallback
pytest-playwright/pytest_playwright/pytest_playwright.py - Async fixtures → Base URL fallback: uses fallback
pytest-playwright-asyncio/pytest_playwright_asyncio/pytest_playwright.py - Sync fixtures → Sync artifact recorder: creates recorder
pytest-playwright/pytest_playwright/pytest_playwright.py - Async fixtures → Async artifact recorder: creates recorder
pytest-playwright-asyncio/pytest_playwright_asyncio/pytest_playwright.py - Sync artifact recorder → Artifact files: writes artifacts
pytest-playwright/pytest_playwright/pytest_playwright.py - Async artifact recorder → Artifact files: writes artifacts
pytest-playwright-asyncio/pytest_playwright_asyncio/pytest_playwright.py