{"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":"python","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,"search_vec":"'1.6.2':14 'activ':8 'associ':27 'built':33 'built-in':32 'compat':43 'current':11 'design':15 'detail':18 'distribut':45 'durat':2,5,35,76 'execut':19 'featur':36 'fixtur':28 'framework':47 'frequent':60 'function':24 'librari':58 'like':48 'minor':64 'multipl':63 'occur':68 'offer':42 'packag':56 'patch':66 'perform':74 'plugin':10,77 'pytest':1,4,9,30,50,72 'pytest-dur':3 'pytest-xdist':49 'releas':67 'report':17 'see':59 'separ':38 'test':23,46,73 'throughout':69 'time':20,40,54,75 'time-travel':53 'travel':55 'unlik':29 'updat':61 'version':13 'xdist':51 'year':71","created_at":"2026-04-11T17:44:02.584864+00:00","updated_at":"2026-04-17T14:19:17.297637+00:00","problems":[{"fix":"Install the plugin in your active virtual environment: `pip install pytest-durations`.","cause":"The pytest-durations plugin is not installed or is not available in the Python environment where pytest is being executed.","error":"ModuleNotFoundError: No module named 'pytest_durations'"},{"fix":"To get detailed test and fixture timings, use the plugin's specific options, for example: `pytest --durations-path durations_report.json`.","cause":"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.","error":"pytest --durations does not show fixture timings"},{"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`.","cause":"The directory specified in the `--durations-path` option for the report file does not exist, preventing the plugin from writing its output.","error":"FileNotFoundError: [Errno 2] No such file or directory: 'some/nonexistent/path/report.json'"},{"fix":"Run pytest with the `--durations-path` option, e.g., `pytest --durations-path=durations.json`","cause":"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.","error":"pytest-durations file not generated"},{"fix":"Upgrade your pytest installation to a compatible version: `pip install --upgrade pytest`","cause":"The installed pytest version is older than the minimum version required by the pytest-durations plugin.","error":"ERROR: the 'pytest-durations' plugin requires pytest>=6.0.0"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"pytest","cli_version":"pytest 9.0.3","type":"library","homepage":null,"github":"https://github.com/blake-r/pytest-durations","docs":null,"changelog":null,"pypi":"https://pypi.org/project/pytest-durations/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["testing"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-04-11","next_check":"2026-07-10","install_tag":null}}