Registry / testing / pytest-durations

pytest-durations

JSON →
library1.6.2pypypiunverified

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.

pip install pytest-durations
INSTALL
IMPORT
SIG · PYTEST-DURATIONS
P
pytest-durations
testingpythonv1.6.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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.
pytest --version
Debug
Known issues
breakingPython 3.9 support was dropped in version 1.6.2. Python 3.8 support was dropped in version 1.5.0. Ensure your Python environment is 3.10 or newer (up to 3.14).
fix
Upgrade to Python 3.10 or a newer compatible version.
affects: >=1.5.0
breakingThe 'avg' column in duration reports was renamed to 'med' in version 1.6.0 to more accurately reflect median durations. Scripts or tools parsing the report output by column name will need updating.
fix
Update parsing logic to expect the 'med' column instead of 'avg'.
affects: >=1.6.0
deprecatedThe command-line option `--pytest-resultlog` was renamed to `--pytest-durations-log` in version 1.6.0 for consistency. While the old option might still work in some versions, it's considered deprecated.
fix
Update scripts to use `--pytest-durations-log` instead of `--pytest-resultlog`.
affects: >=1.6.0
gotchaIn version 1.5.2, the plugin switched from using `time.monotonic()` to `time.time()` to resolve a bug when used in conjunction with the `time-machine` library. If you rely on specific monotonic timing behavior or use `time-machine`, be aware of this change and test your setup accordingly.
fix
Review the impact of `time.time()` vs `time.monotonic()` on your specific use cases, especially with time-traveling libraries. Consider testing against affected versions.
affects: >=1.5.2
gotchaThe plugin's output differs from pytest's built-in `--durations` option. `pytest-durations` aims to provide separate metrics for fixture setup/teardown and test function execution, and supports xdist/time-traveling. Do not confuse the two outputs.
fix
Use `--pytest-durations` for the plugin's enhanced reporting, and be aware of the distinct information it provides compared to the native `--durations`.
affects: *
gotchaThe `--pytest-durations-group-by` option was introduced in 1.6.0 (improved in 1.6.1), allowing grouping by module, class, or function. The default is 'function'. Use `--pytest-durations-group-by=legacy` to revert to previous behavior if your parsing depends on it.
fix
Specify `--pytest-durations-group-by=legacy` if you need the old grouping behavior, or update your parsing logic to handle new grouping options.
affects: >=1.6.0
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'pytest_durations'
The pytest-durations plugin is not installed or is not available in the Python environment where pytest is being executed.
fix
Install the plugin in your active virtual environment: `pip install pytest-durations`.
pytest --durations does not show fixture timings
Users often confuse the built-in `pytest --durations=N` option (which lists N slowest tests) with the `pytest-durations` plugin, which provides detailed reports of all test and fixture durations using different CLI options.
fix
To get detailed test and fixture timings, use the plugin's specific options, for example: `pytest --durations-path durations_report.json`.
FileNotFoundError: [Errno 2] No such file or directory: 'some/nonexistent/path/report.json'
The directory specified in the `--durations-path` option for the report file does not exist, preventing the plugin from writing its output.
fix
Ensure the target directory for the report file exists before running pytest; for example: `mkdir -p some/nonexistent/path && pytest --durations-path some/nonexistent/path/report.json`.
pytest-durations file not generated
The pytest-durations plugin requires the `--durations-path` command-line argument to specify where to save the durations JSON file. Without it, no file will be created.
fix
Run pytest with the `--durations-path` option, e.g., `pytest --durations-path=durations.json`
ERROR: the 'pytest-durations' plugin requires pytest>=6.0.0
The installed pytest version is older than the minimum version required by the pytest-durations plugin.
fix
Upgrade your pytest installation to a compatible version: `pip install --upgrade pytest`
Upgrade
Version history
1.6.2latest on PyPI · released Mar 13, 2026
Audit
Dependencies
pytestrequiredCore testing framework that this plugin extends. Requires pytest>=4.6, with official support for pytest 7.0.0+.
time-machineoptionalExplicitly added for compatibility, especially related to duration measurements when 'time-traveling' is enabled.
pytest-xdistoptionalSupports serialization/deserialization for distributed testing scenarios.
Agent activity
41 hits · last 30 days
node
26
Bingbot
1
Resources
pytest-durations — pip install pytest-durations · libregistry