-
-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
10 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,25 @@ | ||
from __future__ import annotations | ||
|
||
import gc | ||
import platform | ||
|
||
import pytest | ||
|
||
from markupsafe import _escape_inner # type: ignore[attr-defined] | ||
from markupsafe import escape | ||
|
||
|
||
@pytest.mark.skipif( | ||
_escape_inner.__module__ == "markupsafe._native", | ||
reason="only test memory leak with speedups", | ||
) | ||
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 _i in range(20): | ||
for _j in range(1000): | ||
for _ in range(20): | ||
for _ 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 | ||
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tox] | ||
envlist = | ||
py3{12,11,10,9,8} | ||
py3{13,12,11,10,9,8} | ||
pypy310 | ||
style | ||
typing | ||
|