test_leak.py 556 B

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