1import gc 2import platform 3 4import pytest 5 6from markupsafe import escape 7 8 9@pytest.mark.skipif( 10 escape.__module__ == "markupsafe._native", 11 reason="only test memory leak with speedups", 12) 13def test_markup_leaks(): 14 counts = set() 15 16 for _i in range(20): 17 for _j in range(1000): 18 escape("foo") 19 escape("<foo>") 20 escape("foo") 21 escape("<foo>") 22 23 if platform.python_implementation() == "PyPy": 24 gc.collect() 25 26 counts.add(len(gc.get_objects())) 27 28 assert len(counts) == 1 29