-
Notifications
You must be signed in to change notification settings - Fork 785
Expand file tree
/
Copy pathtest_memory_leaks.py
More file actions
40 lines (27 loc) · 1.07 KB
/
test_memory_leaks.py
File metadata and controls
40 lines (27 loc) · 1.07 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
from __future__ import annotations
import gc
import sys
import pytest
from prompt_toolkit.shortcuts.prompt import PromptSession
def _count_prompt_session_instances() -> int:
# Run full GC collection first.
gc.collect()
# Count number of remaining referenced `PromptSession` instances.
objects = gc.get_objects()
return len([obj for obj in objects if isinstance(obj, PromptSession)])
# This test used to fail in GitHub CI, probably due to GC differences.
# Still fails on Windows due to win32.NoConsoleScreenBufferError.
@pytest.mark.skipif(
sys.platform.startswith("win"),
reason="Fails in GitHug CI due to win32.NoConsoleScreenBufferError",
)
def test_prompt_session_memory_leak() -> None:
before_count = _count_prompt_session_instances()
# Somehow in CI/CD, the before_count is > 0
assert before_count == 0
p = PromptSession()
after_count = _count_prompt_session_instances()
assert after_count == before_count + 1
del p
after_delete_count = _count_prompt_session_instances()
assert after_delete_count == before_count