Pytest plugin for reporting running time and peak memory usage
Project description
pytest-resource-usage
This is a personal experiment to add running times and peak memory usage
(including swap) of tests to the output of pytest.
Memory usage is tracked through tracemalloc
, which can have a high
overhead. Since tracemalloc
is a standard library, the only dependency
of pytest-resource-usage
is pytest
.
If you want something more feature-rich and ambitious, you should use pytest-monitor.
Example usage
Reporting is triggered by the presence of the report_duration
and
report_tracemalloc
markers.
from time import sleep
import pytest
@pytest.mark.report_duration
def test_sleep():
sleep(99)
@pytest.mark.report_tracemalloc
@pytest.mark.parametrize("elements", [2_000_000, 1_000_000])
def test_allocate(elements):
_ = list(range(elements))
@pytest.mark.report_duration
@pytest.mark.report_tracemalloc
def test_sleep_trace_overhead():
_ = list(range(100_000))
sleep(0.2)
Running the above tests produces the following pytest
output
============================================== test session starts ===============================================
plugins: pytest_resource_usage-0.0.1
collected 4 items
tests/test_readme.py .... [100%]
================================================= resource usage =================================================
tests/test_readme.py::test_sleep (call) running time: 0:01:39
tests/test_readme.py::test_allocate[2000000] (call) peak allocated memory: 72MB
tests/test_readme.py::test_allocate[1000000] (call) peak allocated memory: 36MB
tests/test_readme.py::test_sleep_trace_overhead (call) peak allocated memory: 3.59MB, running time: 0.228 seconds
========================================= 4 passed in 100.20s (0:01:40) ==========================================
Project details
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
Close
Hashes for pytest_resource_usage-0.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | a8574204a5944263e3714bcaf026b73b239705827145ab96e05cb7836f6446d1 |
|
MD5 | 2deace7538310f90f8b337eca3293a2f |
|
BLAKE2b-256 | 8babe88d05859325581666f285af6f0fa7d2e65911c39f16d7b7610618827a00 |
Close
Hashes for pytest_resource_usage-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4a79541079fa7c451f32c9894b1b4f899b43242628c1e2eb4be5de6aa21bf91c |
|
MD5 | 6e026134103e405bb423e2a3b5ef0176 |
|
BLAKE2b-256 | 95a11662b6c57d21e8d389e2957216786b9811113b01543f33e62c369b2f3b24 |