https://github.com/miketheman/pytest-execution-timer
Measure Pytest execution phases
https://github.com/miketheman/pytest-execution-timer
black performance-analysis pytest pytest-plugin python python3 testing testing-tools
Last synced: 28 days ago
JSON representation
Measure Pytest execution phases
- Host: GitHub
- URL: https://github.com/miketheman/pytest-execution-timer
- Owner: miketheman
- License: mit
- Created: 2021-12-24T22:58:28.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2024-10-08T11:33:27.000Z (about 1 year ago)
- Last Synced: 2024-12-28T11:41:52.584Z (9 months ago)
- Topics: black, performance-analysis, pytest, pytest-plugin, python, python3, testing, testing-tools
- Language: Python
- Homepage: https://pypi.org/project/pytest-execution-timer/
- Size: 19.5 KB
- Stars: 12
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# pytest-execution-timer
[](https://pypi.python.org/pypi/pytest-execution-timer)
[](https://pypi.python.org/pypi/pytest-execution-timer)
[](https://github.com/miketheman/pytest-execution-timer/actions?query=workflow%3A%22Python+Tests%22)
[](https://results.pre-commit.ci/latest/github/miketheman/pytest-execution-timer/main)
[](https://github.com/psf/black)A plugin to use with Pytest to measure execution time of tests.
Distinctly different from the `--durations` option of pytest,
this plugin measures specific pytest startup/collection phases.Leverages `pytest` hooks to measure execution time of phases.
---
## Installation
Requires:
- Python 3.8 or later.
- Pytest 6.2 or later.Install the plugin with any approach for your project.
Some examples:
```shell
pip install pytest-execution-timer
``````shell
poetry add --dev pytest-execution-timer
``````shell
pipenv install --dev pytest-execution-timer
```Or add it to your `requirements.txt` file.
## Usage
Enable the plugin with the `--execution-timer` option when running `pytest`:
```console
$ pytest --execution-timer
...
Durations of pytest phases in seconds (min 100ms):
0.662 pytest_runtestloop
```Control the threshold (default 100ms) by passing `--minimum-duration=`:
```console
$ pytest --execution-timer --minimum-duration=1000 # 1 second
```## Understanding the output
The best ay to start is to compare the difference of the `pytest_runtestloop` duration
and the overall duration of the test run. Example:```console
Durations of pytest phases in seconds (min 100ms):
0.666 pytest_runtestloop
====== 4 passed in 0.68s ======
```In this example, there's not much lost between the test run and the `pytest_runtestloop`
meaning that the startup and collection phases are not taking too much time.If there's a larger difference in the timings,
look to other emitted phases to understand what's taking the most time.These can then be examined directly,
or use other tools like [profilers](https://docs.python.org/3/library/profile.html)
or [import timings](https://docs.python.org/3/using/cmdline.html#cmdoption-X).## License
Distributed under the terms of the MIT license,
"pytest-execution-timer" is free and open source software.
See `LICENSE` for more information.