# pytest conftest Fixture Dependency Graph & mock.patch Leak Detector

Statically analyze a pytest conftest.py chain: render the fixture dependency graph across all five scopes (function/class/module/package/session), detect deeper-conftest overrides, ScopeMismatch edges, and cross-test state pollution — mock.patch().start() without .stop(), monkeypatch leaking from broad-scope fixtures, and with mock.patch held open across yield.

> Canonical page: https://elysiatools.com/en/tools/pytest-conftest-fixture-dependency-graph-and-mock-patch-leak-detector

- **Category:** Development

- **Keywords:** pytest, conftest, fixture, dependency graph, mock.patch leak, monkeypatch, scope mismatch, session fixture, test pollution, static analysis, python testing, fixture scope

## Overview

Paste one or more conftest.py / test files separated by '# --- file: path ---' markers (or upload a .py). The analyzer implements pytest's documented fixture semantics: scope ordering session > package > module > class > function, ScopeMismatch when a broad fixture depends on a narrower one, and test-outward name resolution where the deepest conftest wins. Leak rules: monkeypatch/capsys/tmp_path are function-scoped built-ins whose undo never runs inside a module/session fixture (patches bleed across the session, pytest-mock issue #84 class of bug); patcher.start() without .stop() survives until process exit; a with mock.patch(...) wrapping a yield keeps every test on the patched target. Output: severity-ranked findings, a fixture inventory table and a scope-layered dependency SVG graph.

## Inputs

- **Python sources (conftest chain)** (textarea): # --- file: conftest.py --- import pytest @pytest.fixture(scope="session") def db(): yield 1 …
- **Python file (optional, .py/.txt)** (file)
- **Show built-in fixture nodes in graph** (checkbox)

## When to use

- Debugging flaky pytest test suites where tests fail depending on execution order due to cross-test state pollution.
- Refactoring multi-directory test suites to audit fixture overrides and verify scope hierarchy across conftest.py files.
- Reviewing pull requests to catch unstopped mock.patch().start() calls or monkeypatch misuse in broad-scope fixtures.

## How it works

- Paste conftest.py and test file contents separated by '# --- file: path ---' markers, or upload a .py file.
- The static analyzer parses fixture definitions, scope annotations, dependencies, and mock or patch operations without running code.
- The tool inspects dependency edges for ScopeMismatch errors, tracks deeper conftest fixture overrides, and checks for unstopped patches.
- Inspect the scope-layered dependency SVG graph, fixture inventory table, and severity-ranked pollution findings.

## Use cases

- Visualizing complex fixture dependency graphs and overrides across multi-tier conftest hierarchies.
- Detecting silent patch leaks where mock.patch().start() survives past test boundaries and corrupts test runs.
- Validating scope hierarchies before upgrading pytest or refactoring shared test utilities.

## Frequently asked questions

### Does this tool execute test code or require a Python runtime?

No. The analyzer performs purely static source code parsing without running tests or importing modules.

### How do I analyze multiple conftest.py files simultaneously?

Separate each file in the source input using '# --- file: path/to/conftest.py ---' header markers.

### Why is using monkeypatch in a module or session fixture flagged?

monkeypatch is function-scoped, so its teardown never runs in broad fixtures, causing patches to leak across tests.

### What triggers a ScopeMismatch error in pytest?

A ScopeMismatch occurs when a broader fixture such as session or module depends on a narrower fixture like function.

### What mock.patch issues does the analyzer detect?

It detects patcher.start() calls without corresponding .stop() calls and flags with mock.patch held open across yields.

## Related tools

- [Stryd Running Power Critical Power & W′bal Reconstructor](https://elysiatools.com/en/tools/stryd-running-power-critical-power-and-w-prime-bal-reconstructor): Derive your running Critical Power (CP) and W′ (anaerobic work capacity) from a 3-minute all-out test, power–time trial pairs, or distance–time trials, then replay a Stryd power session (.fit/.tcx/CSV) second by second: W′bal depletion and recovery timeline under the Skiba 2012 integral model and the Froncioni/Skiba/Clarke differential model, time-to-exhaustion forecasts, Stryd zone distribution (Easy/Moderate/Threshold/Interval/Repetition) and a dual-panel power/W′bal chart.
- [Variable Font Axis Instance and CSS Font Variation Settings Builder](https://elysiatools.com/en/tools/variable-font-axis-instance-and-css-font-variation-settings-builder): Upload a variable font (TTF/OTF/WOFF/WOFF2) to inspect its fvar axes and named instances, preview interpolation live in the browser, and generate ready-to-paste font-variation-settings CSS plus the equivalent high-level properties and a variable @font-face block.
- [SQL Explain Plan Visualizer](https://elysiatools.com/en/tools/sql-explain-plan-visualizer): Parse EXPLAIN / EXPLAIN ANALYZE output (PostgreSQL/MySQL/SQLite) into a cost tree, flag estimated-vs-actual row divergence, and suggest indexes
- [Windows PE / Linux ELF / Mach-O Binary Header, Section, Import & Export Inspector](https://elysiatools.com/en/tools/windows-pe-linux-elf-mach-o-binary-header-section-import-export-inspector): Upload a PE-COFF (.exe/.dll), ELF or Mach-O binary and parse its headers end to end: DOS/PE signature, COFF machine, optional header (entry point, image base, subsystem, ASLR/NX/CFG), section table with RVA↔offset mapping, import/export directories, ELF program headers and PIE detection, dynamic symbols and DT_NEEDED, Mach-O load commands and dylibs — with cross-architecture annotations and a hex preview.
- [APNG IDAT/fdAT Chunk, Streaming Deflate Replay and Disposal Method Frame-Timing Analyzer](https://elysiatools.com/en/tools/apng-idat-fdat-chunk-streaming-deflate-replay-and-disposal-method-analyzer): Upload a PNG or APNG and audit the whole animation structure: PNG signature and per-chunk CRC32 checks, IHDR bit depth / color type / interlace, acTL placement and declared frame counts, every fcTL (region bounds inside the canvas, normalized delay fractions, dispose_op none/background/previous, blend_op source/over), the shared fcTL+fdAT sequence-number contract from 0, per-frame replay of the IDAT/fdAT deflate streams with exact decompressed-size verification, and disposal-semantics audit — first-frame PREVIOUS treated as BACKGROUND, zero-delay frames, loop counts, fps and compression ratios.
- [CSV Histogram, Scatter and Box Plot Chart Studio](https://elysiatools.com/en/tools/csv-histogram-scatter-box-plot-chart-studio): Upload or paste a CSV and chart it instantly: histograms with Sturges / Freedman-Diaconis / Scott binning, scatter plots with Pearson r and a least-squares fit, and Tukey box plots — every chart downloadable as PNG and SVG.
- [Image Steganography Embed & Detect](https://elysiatools.com/en/tools/image-steganography-embed-detect): Hide text in a PNG's least-significant bits, extract it back, and run the Westfeld–Pfitzmann chi-square steganalysis with a falling-p curve and LSB plane preview.
- [OCR PDF to Structured JSON Bridge](https://elysiatools.com/en/tools/ocr-pdf-to-structured-json-bridge): Extract the PDF text layer with geometry (lines by y-position, tables by column gaps, headings by font size, colon key-value pairs), then fill a user-supplied JSON Schema field by field — labels matched by normalized keys, values coerced to declared types and validated with ajv.

## Samples

- [Copyright-Free MP3 Audio Samples](https://elysiatools.com/en/samples/mp3-samples): Collection of royalty-free audio samples for testing and development purposes including nature sounds, meditation music, and ambient audio
- [Code Comment Samples](https://elysiatools.com/en/samples/code-comment-samples): Sample code files with various comment styles for testing comment removal
- [QR Code Samples](https://elysiatools.com/en/samples/qrcode-samples): Sample QR code images for testing QR code reading and generation tools
- [GitHub Actions Testing - CI/CD Integration](https://elysiatools.com/en/samples/github-actions-testing): Comprehensive GitHub Actions testing workflows including automated testing, parallel execution, test reporting, caching, and advanced CI/CD patterns for modern development pipelines
