Skip to main content

Downloads

Introduction

Pytest plugin to measure fixture and test durations.

In order to get the pure test setup/teardown durations, the plugin subtracts time taken by fixtures whose scope is larger than "function".

In comparison to the built-in pytest "--durations", this plugin shows fixture durations separately from test function durations and supports xdist and time-traveling packages.

Installation

$ pip install pytest-durations

Plugin options

pytest-durations:
  --pytest-durations=N  Show N slowest setup/test durations (N=0 to disable
                        plugin). Default 30
  --pytest-durations-min=N
                        Minimal duration in seconds for inclusion in slowest
                        list. Default 0.005
  --pytest-durations-log=FILE
                        Result log filename or dash for terminal output. Default
                        "-"
  --pytest-durations-group-by={legacy,module,class,function}
                        Group test durations by module, class, or function. Use
                        legacy grouping for backward compatibility. Default:
                        "function"

Note: Please don't confuse these options with the --durations options that come from pytest itself.

Example of report

========================================= fixture duration top ==========================================
total          name                                                     num med            max
0:00:00.031589 tests/test_options.py::fake_pluginmanager                  3 0:00:00.008776 0:00:00.008867
0:00:00.015807 tests/test_xdist.py::fake_session                          2 0:00:00.007904 0:00:00.007904
0:00:00.014311 tests/test_options.py::fake_config                         2 0:00:00.007155 0:00:00.007155
0:00:00.009118 tests/test_plugin.py::test_plugin_with_options::pytester   3 0:00:00.002232 0:00:00.002415
0:00:00.005009 tests/test_options.py::reload_module                       1 0:00:00.005009 0:00:00.005009
0:00:00.096780 grand total                                              164 0:00:00.000016 0:00:00.000073
======================================== test call duration top =========================================
total          name                                                     num med            max
0:00:00.483961 tests/test_plugin.py::test_plugin_xdist_enabled            1 0:00:00.483961 0:00:00.483961
0:00:00.177326 tests/test_plugin.py::test_plugin_with_options             3 0:00:00.057389 0:00:00.109171
0:00:00.067949 tests/test_plugin.py::test_plugin_with_resultlog           1 0:00:00.067949 0:00:00.067949
0:00:00.066597 tests/test_plugin.py::test_plugin_disable                  1 0:00:00.066597 0:00:00.066597
0:00:00.059509 tests/test_plugin.py::test_plugin_xdist_disabled           1 0:00:00.059509 0:00:00.059509
0:00:00.025053 tests/test_ticker.py::test_freezegun_import_none           1 0:00:00.025053 0:00:00.025053
0:00:00.023706 tests/test_ticker.py::test_get_current_ticks_frozen        2 0:00:00.011853 0:00:00.065801
0:00:00.912538 grand total                                               78 0:00:00.000083 0:00:00.000483
======================================== test setup duration top ========================================
total          name                                                     num med            max
0:00:00.019535 tests/test_options.py::test_pytest_addoption               1 0:00:00.019535 0:00:00.019535
0:00:00.016147 tests/test_options.py::test_pytest_configure_disabled      1 0:00:00.016147 0:00:00.016147
0:00:00.015358 tests/test_options.py::test_pytest_configure               1 0:00:00.015358 0:00:00.015358
0:00:00.010575 tests/test_plugin.py::test_plugin_with_options             3 0:00:00.002773 0:00:00.008465
0:00:00.008763 tests/test_xdist.py::test_pytest_sessionfinish_noxdist     1 0:00:00.008763 0:00:00.008763
0:00:00.007749 tests/test_xdist.py::test_pytest_sessionfinish             1 0:00:00.007749 0:00:00.007749
0:00:00.100089 grand total                                               78 0:00:00.000113 0:00:00.000192
====================================== test teardown duration top =======================================
total          name                                                     num med            max
0:00:00.006716 grand total                                               78 0:00:00.000062 0:00:00.000062

Development

The project uses poetry for dependency management, pytest for testing, and pre-commit for coding standard checks.

$ pip install poetry
$ poetry install
$ pre-commit install
$ pytest

Unreleased

  • todo: describe new features here

Change Log

1.6.4 (Aug 14, 2026)

  • Show max duration instead of min in reports (#47) — fixes a regression from v1.3.1 where the last column was accidentally truncated.

1.6.2 (Mar 13, 2026)

  • drop support python3.9 and add support python3.14

1.6.1 (Aug 29, 2025)

  • Introduced a new --pytest-durations-group-by=none option that preserves the full test node ID, including parameters
  • Removed the need for explicit serialization of Category values when sending CategoryMeasurementsT dictionaries

1.6.0 (Aug 27, 2025)

  • Added support for grouping test durations by module, class, or function (#26)
  • Improved column alignment in duration reports, ensuring test names are left-aligned
  • Renamed the avg column to med in reports, as it correctly represents median durations, not average durations (#24)
  • Refactoring
    • Added a Python script (check_versions.py) to automate checking that the package version is synchronized
    • Renamed the pytest-resultlog option to pytest-durations-log for consistency. The pytest-resultlog option will be deprecated in a future release
    • Converted the internal Category class to inherit from StrEnum for improved type safety and better serialization

To revert to the old behavior for test and fixture names in reports, set the --pytest-durations-group-by option to "legacy".

1.5.2 (Apr 29, 2025)

  • Fix a time-machine time.monotonic() unpatching glitch by using time.time() instead (#19)

1.5.1 (Apr 27, 2025)

  • Add Python 3.13 to supported versions
  • Drop Python 3.8 from supported versions, because of poetry and time_machine dependencies
  • Add time_machine package compatibility (#19)
  • Add README commentary on the difference from pytest builtin "--duration" function (#18)
  • Replace separated code style packages with ruff
  • Upgrade poetry and package dependencies versions

1.4.0 (Mar 18, 2025)

  • Add command line option to write the measure report to a file instead of terminal (#16)

1.3.1 (Sep 11, 2024)

  • Upgrade development dependencies

1.3.0 (Sep 11, 2024)

  • Update supported Python versions

1.2.0 (Apr 22, 2022)

  • Use same width for all reports (#6)
  • Improve test coverage (#7)
  • Continuous delivery GitHub workflow

1.1.0 (Mar 7, 2022)

  • Do not interoperate with xdist if it is disabled or absent

1.0.1 (Feb 14, 2022)

  • Grand total row shows real min/max values instead of averages

1.0.0 (Feb 14, 2022)

  • First Release

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest_durations-1.6.4.tar.gz (13.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_durations-1.6.4-py3-none-any.whl (14.5 kB view details)

Uploaded Python 3

File details

Details for the file pytest_durations-1.6.4.tar.gz.

File metadata

  • Download URL: pytest_durations-1.6.4.tar.gz
  • Upload date:
  • Size: 13.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for pytest_durations-1.6.4.tar.gz
Algorithm Hash digest
SHA256 97842d0709d0484a8d16e3b5847ccef4811b3c9bb32656a6caecea0af4792241
MD5 16834657c6044d0d4c715b6b1e29442f
BLAKE2b-256 3c5071fa4151899c26d160596b30cdc7e0c0db06a845a1038569beb7bb164bf3

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_durations-1.6.4.tar.gz:

Publisher: cicd.yml on blake-r/pytest-durations

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytest_durations-1.6.4-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_durations-1.6.4-py3-none-any.whl
Algorithm Hash digest
SHA256 4568950b7d4ebc111faa93b06c6b4cb900931dc87ca926e837e1a588dd756bd3
MD5 58dd76a55a8ede2d309e3f916a2f1333
BLAKE2b-256 c38d25777269753997a52ad5541ef58e575b97f11391e34d6e8c1976762397a0

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_durations-1.6.4-py3-none-any.whl:

Publisher: cicd.yml on blake-r/pytest-durations

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

1.9.0

2 files

1.8.0

2 files

1.7.1

2 files

1.7.0

2 files

This release

1.6.4 This release

2 files

1.6.3

2 files

1.6.2

2 files

1.6.1

2 files

1.6.0

2 files

1.5.2

2 files

1.5.1

2 files

1.5.0

2 files

1.4.0

2 files

1.3.1

2 files

1.3.0

2 files

1.2.0

2 files

1.1.0

2 files

1.0.1

2 files

1.0.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page