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.
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.
Quickstart
Install from PyPI:
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 (
0.1.0), available on PyPI. The API and report schema may still change. Release history: CHANGELOG · publishing process: docs/pypi.md.
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_setupto record each test's fixture closure.pytest_fixture_setupto measure fixture setup spans.pytest_runtest_logreportto record test outcomes.pytest_sessionfinishto writereport.htmlandreport.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-xdistdistributed 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
- Support: SUPPORT.md
- Security: SECURITY.md
- Code of conduct: CODE_OF_CONDUCT.md
License
MIT. See LICENSE.
Metadata
Release files for pytest-fixture-lens 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pytest_fixture_lens-0.1.1.tar.gz | 211.6 kB | With provenance | Details for pytest_fixture_lens-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pytest_fixture_lens-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for pytest_fixture_lens-0.1.1-py3-none-any.whl |
Total release size: 227.2 kB
Release files / pytest_fixture_lens-0.1.1.tar.gz
| Download URL | pytest_fixture_lens-0.1.1.tar.gz |
|---|---|
| Size | 211.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6c7273022e25a611be259003840669cd2922b160f0f33c9b8b4145bcd50772f8
|
|
BLAKE2b-256 checksum How to use checksums |
a117e87b0e92880bebf2b03273fe80331460cd0d0692ef721ccf1709fec2e215
|
| 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 logRelease files / pytest_fixture_lens-0.1.1-py3-none-any.whl
| Download URL | pytest_fixture_lens-0.1.1-py3-none-any.whl |
|---|---|
| Size | 15.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f0109a71b47da0a8147ba44f46f69a3ce583764ee575b64c1947ad4fef7f65f2
|
|
BLAKE2b-256 checksum How to use checksums |
b56ff3d8092aee9f395e24e452406cfb3cff5a915f73b3d0a4446d8fb44b6722
|
| 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 logSecurity for pytest-fixture-lens 0.1.1
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.
Attestation for pytest_fixture_lens-0.1.1.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 logA 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.