File: test_leak.py

package info (click to toggle)
markupsafe 3.0.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 424 kB
  • sloc: python: 580; ansic: 177; makefile: 16
file content (28 lines) | stat: -rw-r--r-- 744 bytes parent folder | download
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
from __future__ import annotations

import gc

import pytest

from markupsafe import escape


@pytest.mark.thread_unsafe(reason="Tests gc.get_objects()")
def test_markup_leaks() -> None:
    counts = set()
    # Try to start with a "clean" count. Works for PyPy but not 3.13 JIT.
    gc.collect()

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

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

    # Some implementations, such as PyPy and Python 3.13 JIT, end up with 2
    # counts rather than one. Presumably this is internals stabilizing. A leak
    # would presumably have a different count every loop.
    assert len(counts) < 3