bloomberg / pytest-memray

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

limit_memory for parametrized tests #33

Open gaborbernat opened 2 years ago

gaborbernat commented 2 years ago

Handle parametrized tests requiring differing memory limits. Currently, these tests need to be duplicated but we could use a fixture to apply dynamic memory limit or allow limit memory to be a list of limits.

@pablogsal ideas?

@pytest.mark.parametrize("count", [1, 1000])
@pytest.mark.limit_memory("1 MB")  # limit differs per parameter
def test_a(count):
    assert 'a' * count 
pablogsal commented 2 years ago

We may be able to expose a context manager somehow and then pass the count as a value in there.

gaborbernat commented 2 years ago

The problem with the context manager would be that now we move the memory consumption from start/end to test to someplace within the test 🤔 and also open the door for running the memory measurement count multiple times within a test. Not sure how would that integrate with the memory report at the end of the test suite. So doing a context manager would require solving some potentially complicated API questions 🤔

pablogsal commented 2 years ago

So doing a context manager would require solving some potentially complicated API questions 🤔

Well, is not that this problem already doesn't require solving complicated API questions 😅