Skip to main content

English · فارسی

FixtureLens — see which pytest fixtures your tests build, reuse, and pay for

FixtureLens

See which pytest fixtures your tests actually build, reuse, and pay for.

Offline HTML + JSON reports for pytest fixture setup cost, reuse, and dependencies.

PyPI CI License: MIT Python 3.10+ pytest 8/9 Ruff PRs welcome

Quickstart · Demo · What you get · How it works · FAQ · Publishing · PyPI


What problem does it solve?

A slow pytest suite is often not slow because of assertions. It is slow because fixtures — database connections, API clients, temp files, seeded data — are built more often than you think.

FixtureLens answers questions like:

  • Which fixtures cost the most setup time?
  • Which fixtures are requested by many tests but set up only once?
  • Which test triggered a surprising chain of fixture setup?
  • Is a session-scoped fixture accidentally being pulled into a function-scoped chain?

It is not a replacement for pytest, a profiler for your application code, or an LLM tool. It is a small, opt-in pytest plugin that makes fixture setup visible.

Demo

Run the demo:

pytest examples/demo_project/tests --fixture-lens --fixture-lens-dir examples/demo_project

Then open examples/demo_project/report.html.

Terminal demo: pytest --fixture-lens writes an offline report

FixtureLens report preview with hotspots and dependency graph

Quickstart

Install from PyPI (available after the first release — see docs/pypi.md):

pip install pytest-fixture-lens

Or install from a checkout:

python -m pip install -e .

Run your tests with the plugin enabled:

pytest --fixture-lens

Open the report:

.fixturelens/report.html

Machine-readable output:

.fixturelens/report.json

Custom output directory:

pytest --fixture-lens --fixture-lens-dir build/fixturelens

Status: alpha MVP. The distribution name pytest-fixture-lens is planned, but not published to PyPI yet.

What you get

Feature Description
Setup hotspots Fixtures sorted by exclusive setup time.
Dependency graph Fixture-to-fixture graph built from fixture arguments.
Reuse counts Requested vs setups vs reused, per fixture function.
Per-test events Which fixture setup spans happened during each test.
Offline HTML Self-contained report: no network, no external assets.
JSON output Machine-readable report for CI or custom tooling.
Safe failure behavior Reports are written even when tests fail.

CLI options

Option Default Meaning
--fixture-lens off Enable the report.
--fixture-lens-dir DIR .fixturelens Where to write report.html and report.json.

Example terminal summary:

--------------- FixtureLens ---------------
8 tests · 4 fixtures · 121.7 ms exclusive setup · 8 reused setups
report: .fixturelens/report.html

How to read the report

Hotspots

Sorted by exclusive setup time. Exclusive time subtracts nested fixture setup spans so a parent fixture does not get charged again for the full cost of its children.

Requested vs setups vs reused

  • Requested: number of selected tests whose fixture closure includes this fixture.
  • Setups: number of observed setup events for this fixture function.
  • Reused: requested - setups, floored at zero.

A session fixture requested by 20 tests and set up once shows 19 reused setups.

Parametrized fixtures are aggregated by fixture function. Observed parameter indices are kept on setup events.

Graph

Click a node to see scope, source, dependencies, setup counts, and timing.

How it works

FixtureLens uses pytest hooks:

  • pytest_runtest_protocol / pytest_runtest_setup to record each test's fixture closure.
  • pytest_fixture_setup to measure fixture setup spans.
  • pytest_runtest_logreport to record test outcomes.
  • pytest_sessionfinish to write report.html and report.json.

See docs/how-it-works.md for details and docs/report-schema.md for the JSON shape.

Limitations

This MVP is intentionally narrow:

  • Setup spans only; teardown time is not measured.
  • The dependency graph may miss dynamic request.getfixturevalue() calls.
  • Parametrized instances are aggregated by fixture function.
  • pytest-xdist distributed runs are rejected with a clear error.
  • Timings are wall-clock measurements from one run, not a statistically stable benchmark.
  • Reports contain test node IDs, fixture names, and source paths. Review before sharing publicly.

Development

python -m pip install -e ".[dev]"
ruff check .
ruff format --check .
pytest

Run the demo as a smoke test:

pytest examples/demo_project/tests --fixture-lens --fixture-lens-dir examples/demo_project

Regenerate README assets:

python scripts/make_assets.py

Project layout

src/fixturelens/       Plugin, report builder, HTML template
tests/                 pytester-based integration tests
examples/demo_project/ Small demo suite with session/module/function fixtures
docs/                  How it works, JSON schema, FAQ, publishing guide
assets/                Banner, logo, demo GIF, report preview
.github/               CI, issue templates, PR template, Dependabot

Roadmap

Good next contributions:

  • teardown timing,
  • pytest-xdist support,
  • dynamic getfixturevalue() tracking,
  • CSV export,
  • CI budget mode: fail when exclusive setup time exceeds a threshold,
  • optional flamegraph-style timeline per test.

Contributing

See CONTRIBUTING.md. Small, tested changes are welcome. Please do not include real secrets, private test names, or proprietary fixture data in reports or issues.

Support and security

License

MIT. See LICENSE.

Metadata

Release files for pytest-fixture-lens 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytest-fixture-lens 0.1.0
File Size Uploaded Provenance Actions
pytest_fixture_lens-0.1.0.tar.gz 210.2 kB With provenance Details for pytest_fixture_lens-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pytest-fixture-lens 0.1.0
File Interpreter ABI Platform Actions
pytest_fixture_lens-0.1.0-py3-none-any.whl Python 3 none any Details for pytest_fixture_lens-0.1.0-py3-none-any.whl

Total release size: 225.7 kB

Release files / pytest_fixture_lens-0.1.0.tar.gz

Download URL pytest_fixture_lens-0.1.0.tar.gz
Size 210.2 kB
Tags Source
SHA-256 checksum
How to use checksums
d54a86ff2a3db07b170a33f5e10288e888bf16ed57aa653885a8aa67eeb16dd9
BLAKE2b-256 checksum
How to use checksums
d8211d2d8a1dc76c7c2f672116e2ccad79c4c06ea83f985f0aceec936ba53624
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 4, 2026.

Transparency log

Release files / pytest_fixture_lens-0.1.0-py3-none-any.whl

Download URL pytest_fixture_lens-0.1.0-py3-none-any.whl
Size 15.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
da37c1a20770ec14d40b59102e75fc57b2949a8188ccd6180fe5e9517d998194
BLAKE2b-256 checksum
How to use checksums
21d4502e7a39363e37c2fdecaa14caa26cc320174e61c820e3b190f9a89a647e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 4, 2026.

Transparency log

Security for pytest-fixture-lens 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pytest_fixture_lens-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 4, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page