Pytest plugin for reporting running time and peak memory usage
Project description
pytest-tracemalloc
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-tracemalloc
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.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 950979ef1bfadcbed5c1afa22803fb37a34d468a073feccd35a129c4179bf234 |
|
MD5 | bce2a016a41e8dc740ee16c345f03c87 |
|
BLAKE2b-256 | b0e94733075f3c01d3cca6a391512a41ec4671a6298ef09153771eaac0abdc9a |
Close
Hashes for pytest_resource_usage-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cb06cd6f95ed5305f3db8b68dbd01b5d2c9f63acda7ceba26906da15ddaac5d9 |
|
MD5 | 5247b36fb0cf487d3b749e9b38e1d6d3 |
|
BLAKE2b-256 | 3683e13e78b3b2798538674a003ebd4a07e870f38768693453dc461bc8b7e4b8 |