Profilling pytest tests and fixtures
pytest –durations Link to heading
--durations=<n>
outputs the top
pytest --durations=<n>
pyinstrument Link to heading
pip install pyinstrument
pyinstrument -m pytest
pytest-profiling Link to heading
pip install pytest-profiling
+ SnakeViz Link to heading
pytest --profile
pip install snakeviz
snakeviz prof/combined.prof
+ SVG Link to heading
pytest --profile-svg
# open prof/combined.svg
Workaround to time fixtures teardown Link to heading
- Edit file
<venv>/lib/python<version>/site-packages/_pytest/fixtures.py
- Search for
def _teardown_yield_fixture
- Replace
next(it)
withfrom time import time t = time() next(it) print(f"#################################### fixture {fixturefunc} teardown took {d} seconds")