# microsoft/playwright-pytest architecture

> Architecture diagram of the GitHub repository microsoft/playwright-pytest, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/microsoft/playwright-pytest
- Repository: https://github.com/microsoft/playwright-pytest

## Overview

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/pytest_playwright.py`](https://github.com/microsoft/playwright-pytest/blob/main/pytest-playwright/pytest_playwright/pytest_playwright.py) (Sync fixtures), [`pytest-playwright-asyncio/pytest_playwright_asyncio/pytest_playwright.py`](https://github.com/microsoft/playwright-pytest/blob/main/pytest-playwright-asyncio/pytest_playwright_asyncio/pytest_playwright.py) (Async fixtures), [`pytest-playwright/pytest_playwright/_base_url_fallback.py`](https://github.com/microsoft/playwright-pytest/blob/main/pytest-playwright/pytest_playwright/_base_url_fallback.py) (Base URL fallback), [`pytest-playwright-asyncio/pytest_playwright_asyncio/_base_url_fallback.py`](https://github.com/microsoft/playwright-pytest/blob/main/pytest-playwright-asyncio/pytest_playwright_asyncio/_base_url_fallback.py) (Base URL fallback)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_sync["Synchronous plugin"]
  node_sync_plugin["Sync fixtures"]
  node_sync_base["Base URL fallback"]
end

subgraph group_async["Async plugin"]
  node_async_plugin["Async fixtures"]
  node_async_base["Base URL fallback"]
end

subgraph group_artifact["Artifact capture"]
  node_sync_recorder["Sync artifact recorder"]
  node_async_recorder["Async artifact recorder"]
end

node_tests(("Test suite"))
node_pytest(("pytest runner"))
node_playwright["Playwright runtime"]
node_browsers["Browser engines"]
node_artifact_files[("Artifact files")]

node_tests -->|"runs tests"| node_pytest
node_pytest -.->|"loads plugin"| node_sync_plugin
node_pytest -.->|"loads plugin"| node_async_plugin
node_sync_plugin -->|"starts runtime"| node_playwright
node_async_plugin -.->|"starts runtime"| node_playwright
node_sync_plugin -->|"launches browser"| node_browsers
node_async_plugin -->|"launches browser"| node_browsers
node_sync_plugin -->|"uses fallback"| node_sync_base
node_async_plugin -->|"uses fallback"| node_async_base
node_sync_plugin -->|"creates recorder"| node_sync_recorder
node_async_plugin -->|"creates recorder"| node_async_recorder
node_sync_recorder -->|"writes artifacts"| node_artifact_files
node_async_recorder -->|"writes artifacts"| node_artifact_files

click node_sync_plugin "https://github.com/microsoft/playwright-pytest/blob/main/pytest-playwright/pytest_playwright/pytest_playwright.py"
click node_sync_base "https://github.com/microsoft/playwright-pytest/blob/main/pytest-playwright/pytest_playwright/_base_url_fallback.py"
click node_sync_recorder "https://github.com/microsoft/playwright-pytest/blob/main/pytest-playwright/pytest_playwright/pytest_playwright.py"
click node_async_plugin "https://github.com/microsoft/playwright-pytest/blob/main/pytest-playwright-asyncio/pytest_playwright_asyncio/pytest_playwright.py"
click node_async_base "https://github.com/microsoft/playwright-pytest/blob/main/pytest-playwright-asyncio/pytest_playwright_asyncio/_base_url_fallback.py"
click node_async_recorder "https://github.com/microsoft/playwright-pytest/blob/main/pytest-playwright-asyncio/pytest_playwright_asyncio/pytest_playwright.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_sync_plugin,node_sync_base,node_browsers toneBlue
class node_async_plugin,node_async_base,node_artifact_files toneAmber
class node_sync_recorder,node_async_recorder toneMint
class node_tests,node_pytest,node_playwright toneIndigo
```

## Components

### Synchronous plugin

- [Sync fixtures](https://github.com/microsoft/playwright-pytest/blob/main/pytest-playwright/pytest_playwright/pytest_playwright.py): `pytest-playwright/pytest_playwright/pytest_playwright.py`
- [Base URL fallback](https://github.com/microsoft/playwright-pytest/blob/main/pytest-playwright/pytest_playwright/_base_url_fallback.py): `pytest-playwright/pytest_playwright/_base_url_fallback.py`

### Async plugin

- [Async fixtures](https://github.com/microsoft/playwright-pytest/blob/main/pytest-playwright-asyncio/pytest_playwright_asyncio/pytest_playwright.py): `pytest-playwright-asyncio/pytest_playwright_asyncio/pytest_playwright.py`
- [Base URL fallback](https://github.com/microsoft/playwright-pytest/blob/main/pytest-playwright-asyncio/pytest_playwright_asyncio/_base_url_fallback.py): `pytest-playwright-asyncio/pytest_playwright_asyncio/_base_url_fallback.py`

### Artifact capture

- [Sync artifact recorder](https://github.com/microsoft/playwright-pytest/blob/main/pytest-playwright/pytest_playwright/pytest_playwright.py): `pytest-playwright/pytest_playwright/pytest_playwright.py`
- [Async artifact recorder](https://github.com/microsoft/playwright-pytest/blob/main/pytest-playwright-asyncio/pytest_playwright_asyncio/pytest_playwright.py): `pytest-playwright-asyncio/pytest_playwright_asyncio/pytest_playwright.py`

### Other components

- **Test suite**
- **pytest runner**
- **Playwright runtime**
- **Browser engines**
- **Artifact files**

## Connections

- Test suite → pytest runner: runs tests (evidence: `README.md`)
- pytest runner → Sync fixtures: loads plugin
- pytest runner → Async fixtures: loads plugin
- Sync fixtures → Playwright runtime: starts runtime (evidence: `pytest-playwright/pytest_playwright/pytest_playwright.py`)
- Async fixtures → Playwright runtime: starts runtime
- Sync fixtures → Browser engines: launches browser (evidence: `pytest-playwright/pytest_playwright/pytest_playwright.py`)
- Async fixtures → Browser engines: launches browser (evidence: `pytest-playwright-asyncio/pytest_playwright_asyncio/pytest_playwright.py`)
- Sync fixtures → Base URL fallback: uses fallback (evidence: `pytest-playwright/pytest_playwright/pytest_playwright.py`)
- Async fixtures → Base URL fallback: uses fallback (evidence: `pytest-playwright-asyncio/pytest_playwright_asyncio/pytest_playwright.py`)
- Sync fixtures → Sync artifact recorder: creates recorder (evidence: `pytest-playwright/pytest_playwright/pytest_playwright.py`)
- Async fixtures → Async artifact recorder: creates recorder (evidence: `pytest-playwright-asyncio/pytest_playwright_asyncio/pytest_playwright.py`)
- Sync artifact recorder → Artifact files: writes artifacts (evidence: `pytest-playwright/pytest_playwright/pytest_playwright.py`)
- Async artifact recorder → Artifact files: writes artifacts (evidence: `pytest-playwright-asyncio/pytest_playwright_asyncio/pytest_playwright.py`)
