# pytest-dev/pytest architecture

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

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

## Overview

pytest is a Python testing framework: users invoke it to discover tests, configure collection and plugins, prepare fixtures, execute tests, and inspect reports. The graph emphasizes that runtime workflow while retaining documented capabilities such as assertion introspection, unittest support, and plugins. Edges use the README or SOURCE INDEX references in the supplied excerpts; unsampled modules are included where they represent major product capabilities, but their internal wiring is not inferred.

Main entry points: [`src/pytest/__init__.py`](https://github.com/pytest-dev/pytest/blob/main/src/pytest/__init__.py) (Public API), [`src/_pytest/main.py`](https://github.com/pytest-dev/pytest/blob/main/src/_pytest/main.py) (Session and collection), [`src/_pytest/config/__init__.py`](https://github.com/pytest-dev/pytest/blob/main/src/_pytest/config/__init__.py) (Configuration), [`src/_pytest/nodes.py`](https://github.com/pytest-dev/pytest/blob/main/src/_pytest/nodes.py) (Collection nodes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry and configuration"]
  node_api["Public API<br/>[__init__.py]"]
  node_config["Configuration<br/>[__init__.py]"]
  node_arguments["CLI options<br/>[argparsing.py]"]
end

subgraph group_discovery["Discovery and execution"]
  node_session["Session and collection<br/>[main.py]"]
  node_pythoncollect["Python collection<br/>[python.py]"]
  node_nodes["Collection nodes<br/>[nodes.py]"]
  node_fixtures["Fixture management<br/>[fixtures.py]"]
  node_runner["Test runner<br/>[runner.py]"]
  node_marks["Marks and selection<br/>[structures.py]"]
end

subgraph group_support["Test support"]
  node_assertions["Assert rewriting<br/>[rewrite.py]"]
  node_code["Traceback inspection<br/>[code.py]"]
  node_doctest["Doctest support<br/>[doctest.py]"]
  node_unittest["Unittest support<br/>[unittest.py]"]
  node_capture["Output capture<br/>[capture.py]"]
end

subgraph group_results["Results and diagnostics"]
  node_reports["Test reports<br/>[reports.py]"]
  node_terminal["Terminal reporting<br/>[terminal.py]"]
  node_warnings["Warning handling<br/>[warnings.py]"]
  node_cache[("Run cache<br/>[cacheprovider.py]")]
end

node_user(("Test author"))

node_user -->|"runs tests"| node_session
node_api -->|"exports API"| node_config
node_config -->|"configures options"| node_arguments
node_session -->|"uses settings"| node_config
node_session -->|"collects nodes"| node_nodes
node_session -->|"runs protocol"| node_runner
node_pythoncollect -->|"creates nodes"| node_nodes
node_pythoncollect -->|"resolves fixtures"| node_fixtures
node_pythoncollect -->|"uses marks"| node_marks
node_fixtures -->|"binds to nodes"| node_nodes
node_nodes -->|"exposes marks"| node_marks
node_session -->|"collects reports"| node_reports
node_api -->|"exports assertion support"| node_assertions
node_assertions -->|"uses traceback tools"| node_code
node_api -->|"exports doctest support"| node_doctest
node_api -->|"exports unittest support"| node_unittest
node_api -->|"exports capture support"| node_capture
node_api -->|"exports cache support"| node_cache
node_config -->|"loads plugin"| node_cache
node_reports -.->|"renders reports"| node_terminal
node_api -->|"exports reporter"| node_terminal
node_config -->|"configures filters"| node_warnings
node_reports -.->|"formats failures"| node_code

click node_api "https://github.com/pytest-dev/pytest/blob/main/src/pytest/__init__.py"
click node_config "https://github.com/pytest-dev/pytest/blob/main/src/_pytest/config/__init__.py"
click node_arguments "https://github.com/pytest-dev/pytest/blob/main/src/_pytest/config/argparsing.py"
click node_session "https://github.com/pytest-dev/pytest/blob/main/src/_pytest/main.py"
click node_pythoncollect "https://github.com/pytest-dev/pytest/blob/main/src/_pytest/python.py"
click node_nodes "https://github.com/pytest-dev/pytest/blob/main/src/_pytest/nodes.py"
click node_fixtures "https://github.com/pytest-dev/pytest/blob/main/src/_pytest/fixtures.py"
click node_runner "https://github.com/pytest-dev/pytest/blob/main/src/_pytest/runner.py"
click node_marks "https://github.com/pytest-dev/pytest/blob/main/src/_pytest/mark/structures.py"
click node_assertions "https://github.com/pytest-dev/pytest/blob/main/src/_pytest/assertion/rewrite.py"
click node_code "https://github.com/pytest-dev/pytest/blob/main/src/_pytest/_code/code.py"
click node_doctest "https://github.com/pytest-dev/pytest/blob/main/src/_pytest/doctest.py"
click node_unittest "https://github.com/pytest-dev/pytest/blob/main/src/_pytest/unittest.py"
click node_capture "https://github.com/pytest-dev/pytest/blob/main/src/_pytest/capture.py"
click node_reports "https://github.com/pytest-dev/pytest/blob/main/src/_pytest/reports.py"
click node_terminal "https://github.com/pytest-dev/pytest/blob/main/src/_pytest/terminal.py"
click node_warnings "https://github.com/pytest-dev/pytest/blob/main/src/_pytest/warnings.py"
click node_cache "https://github.com/pytest-dev/pytest/blob/main/src/_pytest/cacheprovider.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_api,node_config,node_arguments toneBlue
class node_session,node_pythoncollect,node_nodes,node_fixtures,node_runner,node_marks toneAmber
class node_assertions,node_code,node_doctest,node_unittest,node_capture toneMint
class node_reports,node_terminal,node_warnings,node_cache toneRose
class node_user toneIndigo
```

## Components

### Entry and configuration

- [Public API](https://github.com/pytest-dev/pytest/blob/main/src/pytest/__init__.py): `src/pytest/__init__.py`
- [Configuration](https://github.com/pytest-dev/pytest/blob/main/src/_pytest/config/__init__.py): `src/_pytest/config/__init__.py`
- [CLI options](https://github.com/pytest-dev/pytest/blob/main/src/_pytest/config/argparsing.py): `src/_pytest/config/argparsing.py`

### Discovery and execution

- [Session and collection](https://github.com/pytest-dev/pytest/blob/main/src/_pytest/main.py): `src/_pytest/main.py`
- [Python collection](https://github.com/pytest-dev/pytest/blob/main/src/_pytest/python.py): `src/_pytest/python.py`
- [Collection nodes](https://github.com/pytest-dev/pytest/blob/main/src/_pytest/nodes.py): `src/_pytest/nodes.py`
- [Fixture management](https://github.com/pytest-dev/pytest/blob/main/src/_pytest/fixtures.py): `src/_pytest/fixtures.py`
- [Test runner](https://github.com/pytest-dev/pytest/blob/main/src/_pytest/runner.py): `src/_pytest/runner.py`
- [Marks and selection](https://github.com/pytest-dev/pytest/blob/main/src/_pytest/mark/structures.py): `src/_pytest/mark/structures.py`

### Test support

- [Assert rewriting](https://github.com/pytest-dev/pytest/blob/main/src/_pytest/assertion/rewrite.py): `src/_pytest/assertion/rewrite.py`
- [Traceback inspection](https://github.com/pytest-dev/pytest/blob/main/src/_pytest/_code/code.py): `src/_pytest/_code/code.py`
- [Doctest support](https://github.com/pytest-dev/pytest/blob/main/src/_pytest/doctest.py): `src/_pytest/doctest.py`
- [Unittest support](https://github.com/pytest-dev/pytest/blob/main/src/_pytest/unittest.py): `src/_pytest/unittest.py`
- [Output capture](https://github.com/pytest-dev/pytest/blob/main/src/_pytest/capture.py): `src/_pytest/capture.py`

### Results and diagnostics

- [Test reports](https://github.com/pytest-dev/pytest/blob/main/src/_pytest/reports.py): `src/_pytest/reports.py`
- [Terminal reporting](https://github.com/pytest-dev/pytest/blob/main/src/_pytest/terminal.py): `src/_pytest/terminal.py`
- [Warning handling](https://github.com/pytest-dev/pytest/blob/main/src/_pytest/warnings.py): `src/_pytest/warnings.py`
- [Run cache](https://github.com/pytest-dev/pytest/blob/main/src/_pytest/cacheprovider.py): `src/_pytest/cacheprovider.py`

### Other components

- **Test author**

## Connections

- Test author → Session and collection: runs tests
- Public API → Configuration: exports API (evidence: `src/pytest/__init__.py`)
- Configuration → CLI options: configures options (evidence: `src/_pytest/config/__init__.py`)
- Session and collection → Configuration: uses settings (evidence: `src/_pytest/main.py`)
- Session and collection → Collection nodes: collects nodes (evidence: `src/_pytest/main.py`)
- Session and collection → Test runner: runs protocol (evidence: `src/_pytest/main.py`)
- Python collection → Collection nodes: creates nodes (evidence: `src/_pytest/python.py`)
- Python collection → Fixture management: resolves fixtures (evidence: `src/_pytest/python.py`)
- Python collection → Marks and selection: uses marks (evidence: `src/_pytest/python.py`)
- Fixture management → Collection nodes: binds to nodes (evidence: `src/_pytest/fixtures.py`)
- Collection nodes → Marks and selection: exposes marks (evidence: `src/_pytest/nodes.py`)
- Session and collection → Test reports: collects reports (evidence: `src/_pytest/main.py`)
- Public API → Assert rewriting: exports assertion support (evidence: `src/pytest/__init__.py`)
- Assert rewriting → Traceback inspection: uses traceback tools (evidence: `src/_pytest/assertion/rewrite.py`)
- Public API → Doctest support: exports doctest support (evidence: `src/pytest/__init__.py`)
- Public API → Unittest support: exports unittest support (evidence: `src/pytest/__init__.py`)
- Public API → Output capture: exports capture support (evidence: `src/pytest/__init__.py`)
- Public API → Run cache: exports cache support (evidence: `src/pytest/__init__.py`)
- Configuration → Run cache: loads plugin (evidence: `src/_pytest/config/__init__.py`)
- Test reports → Terminal reporting: renders reports
- Public API → Terminal reporting: exports reporter (evidence: `src/pytest/__init__.py`)
- Configuration → Warning handling: configures filters (evidence: `src/_pytest/warnings.py`)
- Test reports → Traceback inspection: formats failures
