def test_base_dynamic_memory_leak_check(): # Make sure calling this monitoring function doesn't cause a memory # leak on it own dynamic_mem = OS.get_dynamic_memory_usage() dynamic_mem2 = OS.get_dynamic_memory_usage() dynamic_leak = dynamic_mem2 - dynamic_mem assert dynamic_leak == 0
def check_memory_leak(fn): dynamic_mem_start = OS.get_dynamic_memory_usage() static_mem_start = OS.get_static_memory_usage() fn() # TODO: force garbage collection on pypy static_mem_end = OS.get_static_memory_usage() dynamic_mem_end = OS.get_dynamic_memory_usage() static_leak = static_mem_end - static_mem_start dynamic_leak = dynamic_mem_end - dynamic_mem_start assert static_leak == 0 assert dynamic_leak == 0