Pytest plugin reporting fixtures and test functions execution time.
Project description
Introduction
Pytest plugin to measure fixture and test durations.
In order to get the pure test setup/teardown durations, plugin subtracts time taken by fixtures which scope is larger than "function".
In comparison to the builtin pytest "--durations", the plugin shows fixture durations separately from test function durations and supports xdist and time travelling 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-resultlog=FILE
Result log filename or dash for terminal output.
Default "-"
Note: please don't be mistaken by --durations
options which comes from pytest itself.
Example of report
============================== fixture duration top ==============================
total name num avg min
0:00:00.115563 fake_pluginmanager 3 0:00:00.034653 0:00:00.033694
0:00:00.060115 fake_config 2 0:00:00.030057 0:00:00.029842
0:00:00.048612 fake_session 2 0:00:00.024306 0:00:00.023556
0:00:00.016073 fake_node 2 0:00:00.008037 0:00:00.008029
0:00:00.012089 pytester 6 0:00:00.001444 0:00:00.001330
0:00:00.008237 fake_parser 1 0:00:00.008237 0:00:00.008237
0:00:00.265457 grand total 78 0:00:00.000031 0:00:00.000018
============================= test call duration top =============================
total name num avg min
0:00:00.755826 test_plugin_xdist_enabled 1 0:00:00.755826 0:00:00.755826
0:00:00.246548 test_plugin_with_options 3 0:00:00.081849 0:00:00.081029
0:00:00.158057 test_get_test_key 9 0:00:00.017376 0:00:00.016729
0:00:00.121555 test_plugin_disable 1 0:00:00.121555 0:00:00.121555
0:00:00.078009 test_plugin_xdist_disabled 1 0:00:00.078009 0:00:00.078009
0:00:00.037713 test_get_current_ticks_frozen 1 0:00:00.037713 0:00:00.037713
0:00:01.405064 grand total 31 0:00:00.000708 0:00:00.000162
============================= test setup duration top ============================
total name num avg min
0:00:00.065316 test_pytest_configure_disabled 1 0:00:00.065316 0:00:00.065316
0:00:00.063908 test_pytest_configure 1 0:00:00.063908 0:00:00.063908
0:00:00.055924 test_pytest_addoption 1 0:00:00.055924 0:00:00.055924
0:00:00.025543 test_pytest_sessionfinish_noxdist 1 0:00:00.025543 0:00:00.025543
0:00:00.024043 test_pytest_sessionfinish 1 0:00:00.024043 0:00:00.024043
0:00:00.011220 test_plugin_with_options 3 0:00:00.002642 0:00:00.002580
0:00:00.008443 test_pytest_testnodedown_noxdist 1 0:00:00.008443 0:00:00.008443
0:00:00.008431 test_pytest_testnodedown 1 0:00:00.008431 0:00:00.008431
0:00:00.274801 grand total 31 0:00:00.002182 0:00:00.000149
=========================== test teardown duration top ===========================
total name num avg min
0:00:00.007093 grand total 31 0:00:00.000178 0:00:00.000126
=============================== 31 passed in 1.77s ===============================
Development
Project uses poetry for dependencies management, pytest for testing and pre-commit for coding standard checks.
$ pip install poetry
$ poetry install
$ pre-commit install
$ pytest tests
Change Log
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pytest_durations-1.5.2.tar.gz
.
File metadata
- Download URL: pytest_durations-1.5.2.tar.gz
- Upload date:
- Size: 8.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
953a5b84b268d37fbf98fd0818cb60d573c183fc9b0d9ba74b05bd9b5592b751
|
|
MD5 |
6bbd082af0f14a1782cc5c929f002abb
|
|
BLAKE2b-256 |
2cd28d3c4194e4419a4f24a7ba01e88532631617fa0a7b73055ddcf13de9553c
|
File details
Details for the file pytest_durations-1.5.2-py3-none-any.whl
.
File metadata
- Download URL: pytest_durations-1.5.2-py3-none-any.whl
- Upload date:
- Size: 11.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
76e0c95cb4d6e2496f1a06e52bb94258a6781be8f9198fe1b2055451a1f0c90e
|
|
MD5 |
bbb47e5830aab36867629eae92a8bf72
|
|
BLAKE2b-256 |
00ae36c772cc7dcf8981780a2c571bda68fd27a2c12fc190229df8d74bc1f419
|