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 --lf reruns only the tests that failed last time

Python
~/tips/tip-python-pytest-last-failed

python3 -m pytest --lf

Reruns just the previously failing tests, or runs them first, so feedback arrives in seconds.

When three tests out of six hundred fail, I do not want to wait for the other five hundred ninety-seven again.

python3 -m pytest --lf
python3 -m pytest --ff -x

--lf (--last-failed) runs only the tests that failed in the previous run, which pytest remembers in the .pytest_cache directory. --ff (--failed-first) runs the failures first and then everything else, and -x stops at the first failure. If nothing failed last time, --lf runs the whole suite. Add .pytest_cache to your .gitignore. Combine it with -q for compact output while you fix things one by one.

Further reading: pytest cache 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