Pytest plugin reporting fixtures and test functions execution time.
Actively maintained. Last release 13 days ago, commits in 6 of the last 26 weeks. A safe choice.
pip install pytest-durationsIntroduction
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 --help
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"
--pytest-durations-time-format={clock,auto,short}
How to format durations in the report. "clock" shows the
full datetime-style value, "short" a compact H:MM:SS, and
"auto" picks one readable form based on the report
magnitude. Default: "clock"
--pytest-durations-show=SECTIONS
Comma-separated list of report sections to show:
"fixture", "call", "setup", "teardown". Default: show
all sections.
--pytest-durations-columns=COLUMNS
Comma-separated list of stat columns to show: "total",
"num", "min", "med", "max". The test/fixture name is
always shown second, and the first listed column is used
to sort the report. Default: total,num,med,max.
--pytest-durations-json=FILE
Export timing data as JSON to FILE (use "-" for
stdout). Written in addition to the terminal report
unless --pytest-durations=0.
--pytest-durations-baseline=[FILE]
Compare the run against a baseline duration file and
update it. If FILE is omitted,
".pytest_durations_baseline.json" in the rootdir is
used. Comparison output is shown even when
--pytest-durations=0.