def interpret(func, values, view='auto', viewbefore='auto', policy=None, backendopt=False, config=None, malloc_check=True, **kwargs): interp, graph = get_interpreter(func, values, view, viewbefore, policy, backendopt=backendopt, config=config, **kwargs) if not malloc_check: result = interp.eval_graph(graph, values) else: prev = leakfinder.start_tracking_allocations() try: result = interp.eval_graph(graph, values) finally: leaks = leakfinder.stop_tracking_allocations(False, prev) if leaks: raise leakfinder.MallocMismatch(leaks) return result
def test_malloc_mismatch(): import sys, traceback, cStringIO sio = cStringIO.StringIO() traceback.print_stack(sys._getframe(), limit=10, file=sio) tb = sio.getvalue() e = leakfinder.MallocMismatch({1234: tb, 2345: tb}) print str(e) # grouped entries for 1234 and 2345 assert '1234:\n2345:\n' in str(e) or '2345:\n1234:\n' in str(e) assert tb[-80:] in str(e)
def pytest_runtest_teardown(self, __multicall__, item): __multicall__.execute() if not isinstance(item, py.test.collect.Function): return if (not getattr(item.obj, 'dont_track_allocations', False) and leakfinder.TRACK_ALLOCATIONS): item._pypytest_leaks = leakfinder.stop_tracking_allocations(False) else: # stop_tracking_allocations() already called item._pypytest_leaks = None # check for leaks, but only if the test passed so far if getattr(item, '_success', False) and item._pypytest_leaks: raise leakfinder.MallocMismatch(item._pypytest_leaks)
def pytest_runtest_teardown(self, item): if not isinstance(item, py.test.collect.Function): return if (not getattr(item.obj, 'dont_track_allocations', False) and leakfinder.TRACK_ALLOCATIONS): kwds = {} try: kwds['do_collection'] = item.track_allocations_collect except AttributeError: pass item._pypytest_leaks = leakfinder.stop_tracking_allocations( False, **kwds) else: # stop_tracking_allocations() already called item._pypytest_leaks = None # check for leaks, but only if the test passed so far if getattr(item, '_success', False) and item._pypytest_leaks: raise leakfinder.MallocMismatch(item._pypytest_leaks)