Pytest Durations

1.6.2 · active · verified Sat Apr 11

pytest-durations is an active pytest plugin, currently at version 1.6.2, designed to report detailed execution times for both test functions and their associated fixtures. Unlike pytest's built-in `--durations` feature, it separates these timings and offers compatibility with distributed testing frameworks like pytest-xdist and time-traveling packages. The library sees frequent updates, with multiple minor and patch releases occurring throughout the year.

Warnings

Install

Quickstart

To use pytest-durations, simply install the plugin. It integrates automatically with pytest. Create a test file, then run pytest with the `--pytest-durations=N` option to show the N slowest durations. You can also specify `--pytest-durations-log=FILE` to output results to a file.

import pytest
import time

def test_fast_example():
    time.sleep(0.01)
    assert True

def test_slow_example_with_fixture(my_fixture):
    time.sleep(0.05)
    assert my_fixture == "setup_done"

@pytest.fixture
def my_fixture():
    time.sleep(0.02)
    yield "setup_done"
    time.sleep(0.01)

# To run: Save the above as test_durations.py and run 'pytest --pytest-durations=5' in the terminal.

view raw JSON →