test_leak.py 568 B

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