blob: c9de47513e2b7490492c88c60a8266178577ca2c (
plain) (
blame)
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
|