pytest-memrayΒΆ

A pytest plugin for easy integration of memray in your test suite. It can produce reports like:

$ pytest --memray /w/demo 
=================================== test session starts ====================================
platform linux -- Python 3.12.0, pytest-8.1.1, pluggy-1.4.0
rootdir: /home/docs/checkouts/readthedocs.org/user_builds/pytest-memray/checkouts/latest
configfile: pyproject.toml
plugins: memray-1.5.1.dev23+g0654e6b
collected 2 items

demo/test_ok.py .M                                                                   [100%]

========================================= FAILURES =========================================
____________________________________ test_memory_exceed ____________________________________
Test was limited to 100.0KiB but allocated 117.2KiB
------------------------------------ memray-max-memory -------------------------------------
List of allocations:
    - 117.2KiB allocated here:
        test_memory_exceed:/w/demo/test_ok.py:17
        ...

====================================== MEMRAY REPORT =======================================
Allocation results for docs/demo/test_ok.py::test_memory_exceed at the high watermark

	 πŸ“¦ Total memory allocated: 117.2KiB
	 πŸ“ Total allocations: 1
	 πŸ“Š Histogram of allocation sizes: |β–ˆ|
	 πŸ₯‡ Biggest allocating functions:
		- test_memory_exceed:/w/demo/test_ok.py:17 -> 117.2KiB


Allocation results for docs/demo/test_ok.py::test_track at the high watermark

	 πŸ“¦ Total memory allocated: 39.1KiB
	 πŸ“ Total allocations: 1
	 πŸ“Š Histogram of allocation sizes: |β–ˆ|
	 πŸ₯‡ Biggest allocating functions:
		- test_track:/w/demo/test_ok.py:12 -> 39.1KiB


================================= short test summary info ==================================
MEMORY PROBLEMS demo/test_ok.py::test_memory_exceed
=============================== 1 failed, 1 passed in 0.04s ================================