The pytest-memray plugin does it out of the box. Link: https://pytest-memray.readthedocs.io/en/latest/index.html.
pytest-memray