{"id":3772,"library":"pytest-durations","title":"Pytest Durations","description":"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.","status":"active","version":"1.6.2","language":"en","source_language":"en","source_url":"https://github.com/blake-r/pytest-durations","tags":["pytest","testing","performance","timing","durations","plugin"],"install":[{"cmd":"pip install pytest-durations","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Core testing framework that this plugin extends. Requires pytest>=4.6, with official support for pytest 7.0.0+.","package":"pytest","optional":false},{"reason":"Explicitly added for compatibility, especially related to duration measurements when 'time-traveling' is enabled.","package":"time-machine","optional":true},{"reason":"Supports serialization/deserialization for distributed testing scenarios.","package":"pytest-xdist","optional":true}],"imports":[],"quickstart":{"code":"import pytest\nimport time\n\ndef test_fast_example():\n    time.sleep(0.01)\n    assert True\n\ndef test_slow_example_with_fixture(my_fixture):\n    time.sleep(0.05)\n    assert my_fixture == \"setup_done\"\n\n@pytest.fixture\ndef my_fixture():\n    time.sleep(0.02)\n    yield \"setup_done\"\n    time.sleep(0.01)\n\n# To run: Save the above as test_durations.py and run 'pytest --pytest-durations=5' in the terminal.","lang":"python","description":"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."},"warnings":[{"fix":"Upgrade to Python 3.10 or a newer compatible version.","message":"Python 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).","severity":"breaking","affected_versions":">=1.5.0"},{"fix":"Update parsing logic to expect the 'med' column instead of 'avg'.","message":"The '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.","severity":"breaking","affected_versions":">=1.6.0"},{"fix":"Update scripts to use `--pytest-durations-log` instead of `--pytest-resultlog`.","message":"The 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.","severity":"deprecated","affected_versions":">=1.6.0"},{"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.","message":"In 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.","severity":"gotcha","affected_versions":">=1.5.2"},{"fix":"Use `--pytest-durations` for the plugin's enhanced reporting, and be aware of the distinct information it provides compared to the native `--durations`.","message":"The 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.","severity":"gotcha","affected_versions":"*"},{"fix":"Specify `--pytest-durations-group-by=legacy` if you need the old grouping behavior, or update your parsing logic to handle new grouping options.","message":"The `--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.","severity":"gotcha","affected_versions":">=1.6.0"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}