pytest-memray icon indicating copy to clipboard operation
pytest-memray copied to clipboard

limit_memory for parametrized tests

Open gaborbernat opened this issue 3 years ago • 3 comments

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 

gaborbernat avatar May 31 '22 18:05 gaborbernat

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

pablogsal avatar May 31 '22 23:05 pablogsal

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 🤔

gaborbernat avatar May 31 '22 23:05 gaborbernat

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 😅

pablogsal avatar May 31 '22 23:05 pablogsal