bloomberg / pytest-memray

pytest plugin for easy integration of memray memory profiler
https://pytest-memray.readthedocs.io/en/latest/
Apache License 2.0
323 stars 23 forks source link

Documentation is slightly ambiguous about meaning of @pytest.mark.limit_memory() #115

Closed itamarst closed 3 months ago

itamarst commented 3 months ago

The docs say "Fail the execution of the test if the test allocates more memory than allowed." This has two possible meanings:

  1. Total allocated memory, ignoring deallocations.
  2. Peak allocated memory, taking deallocations into account.

The difference comes into play in a test like this:

@pytest.mark.limit_memory("100 MB")
def test_alloc():
    b = b"X" * 90_000_000
    del b
    b2 = b"X" * 90_000_000
    del b2

This passes, suggesting that the second meaning is the one meant by the docs. You could clarify this to users by adding the work "peak" to the docs.

pablogsal commented 3 months ago

Thanks a lot @itamarst! We could also offer an interface to do the same but for (1). What do you think?

itamarst commented 3 months ago

Thank you! I don't have a particular use case for that, and... the main impact is typically performance? And as a Python programmer that's probably the least of your worries :grin: