memray
memray copied to clipboard
exercise_3 solution not passing memory test
exercise_3 solution not passing memory test
Running the solution for exercise_3 fails the memory test.
$ cp -v {solutions/,}exercise_3/lru_cache.py
'solutions/exercise_3/lru_cache.py' -> 'exercise_3/lru_cache.py'
$ pytest tests/test_exercise_3.py -x
=================================================== test session starts ===================================================
platform linux -- Python 3.13.1, pytest-8.3.5, pluggy-1.5.0
rootdir: /tmp/memray
configfile: pyproject.toml
plugins: memray-1.7.0
collected 8 items
tests/test_exercise_3.py M
======================================================== FAILURES =========================================================
_____________________________________________________ test_lru_cache ______________________________________________________
Test was limited to 75.0MiB but allocated 155.0MiB
-------------------------------------------------- Captured stdout call ---------------------------------------------------
[(0, 96950), (5, 32150), (6, 22950), (2, 22450), (4, 22450), (8, 22450), (1, 7650), (7, 7650), (3, 7650), (9, 7650)]
[(0, 388900), (5, 129300), (6, 90900), (2, 89900), (4, 89900), (8, 89900), (1, 30300), (7, 30300), (3, 30300), (9, 30300)]
---------------------------------------------------- memray-max-memory ----------------------------------------------------
List of allocations:
- 72.1KiB allocated here:
generate_factorial_plus_last_digit:/tmp/memray/docs/tutorials/exercise_3/lru_cache.py:23
...
- 9.2MiB allocated here:
generate_factorial_plus_last_digit:/tmp/memray/docs/tutorials/exercise_3/lru_cache.py:23
...
- 118.7MiB allocated here:
_uncached_factorial_plus:/tmp/memray/docs/tutorials/exercise_3/lru_cache.py:16
...
- 27.0MiB allocated here:
_uncached_factorial_plus:/tmp/memray/docs/tutorials/exercise_3/lru_cache.py:16
...
================================================= short test summary info =================================================
MEMORY PROBLEMS tests/test_exercise_3.py::test_lru_cache
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
==================================================== 1 failed in 2.66s ====================================================
$ pip list | grep memray
memray 1.17.0
pytest-memray 1.7.0
In summary, the solution allocates 155MiB, but the test enforces a maximum of 75MiB, so it fails.
Idea: Add to CI a check that ensures:
- the exercise implementation fails the test (as intended),
- but the solution version passes.
Question: How was the 75MiB threshold calculated for this test?
CC @statkute
CC @jcarnaxide as well