Back to labs main.

Calmcode Labs Presents

pytest-duration-insights logopytest-duration-insights.

Our 3rd experiment involves test durations.

Large projects tend to have a lot of unit tests. Unit tests are definately a good idea, but as the project matures there tends to be a bit of bloat. Tests keep on being added and eventually this might lead to a project that is slow to iterate on.

That's why we figured it'd be a good idea to create a tool that makes it easier to understand where the long-running tests are. It might help package maintainers to start working on a more lightweight CI. The name of the tool is pytest-duration-insights and it's available for download today.

How it Works

The pytest-duration-insights tool is a dashboard on top of the report given by pytest-reportlog. You can use pytest-reportlog to first generate a .jsonl file with pytest duration statistics. After that pytest-duration-insights will turn that into a dashboard that gives you insights.

You can install the tool with pip.

pip install pytest-reportlog pytest-duration-insights

Once it's installed you can run the report and view the dashboard.

pytest --report-log reportlog.jsonl
pytest-duration-insights explore reportlog.jsonl

The resulting dashboard gives you an interactive widget that allows you to explore different test files. You can use the flatmap to zoom in and out or use the tree view to check the stats in more detail.



You can find the project on github together with a live demo.

The project is very much open to ideas. It's pretty good to give a first order impression of where to find long-running tests but there's certainly more things that we might be able to do.

Back to labs main.