summaryrefslogtreecommitdiff
path: root/tests/test_leak.py
blob: 55b10b98a42a49d7a912d0a29882e60fecf62c2b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import gc
import platform

import pytest

from markupsafe import escape


@pytest.mark.skipif(
    escape.__module__ == "markupsafe._native",
    reason="only test memory leak with speedups",
)
def test_markup_leaks():
    counts = set()

    for _i in range(20):
        for _j in range(1000):
            escape("foo")
            escape("<foo>")
            escape("foo")
            escape("<foo>")

        if platform.python_implementation() == "PyPy":
            gc.collect()

        counts.add(len(gc.get_objects()))

    assert len(counts) == 1