brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: python -m pytest --durations=5 lists the slowest tests

Python
~/tips/tip-python-pytest-show-slowest-tests

python3 -m pytest --durations=5

Prints the slowest phases of a test run so you know where the time goes.

A test suite gets slow one test at a time, and I would rather see the culprits than guess.

python3 -m pytest --durations=5
python3 -m pytest --durations=0 -vv

--durations=5 prints the five slowest setup, call and teardown phases at the end of the run. --durations=0 prints all of them, and pytest hides entries below 0.005 seconds unless you add -vv. The output separates setup from the test body, so you can tell a slow fixture from a slow test. Run it a couple of times before you trust the numbers, because a cold cache skews the first run.

Further reading: pytest usage documentation

More Python tips import asyncio from enum import StrEnum, auto except* ValueError as eg: import pytest pytest --maxfail=2 All Python tips (107) All topics

Link