summaryrefslogtreecommitdiffstats
path: root/tests/test_memory_leaks.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 16:35:31 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 16:35:31 +0000
commit4f1a3b5f9ad05aa7b08715d48909a2b06ee2fcb1 (patch)
treee5dee7be2f0d963da4faad6517278d03783e3adc /tests/test_memory_leaks.py
parentInitial commit. (diff)
downloadprompt-toolkit-4f1a3b5f9ad05aa7b08715d48909a2b06ee2fcb1.tar.xz
prompt-toolkit-4f1a3b5f9ad05aa7b08715d48909a2b06ee2fcb1.zip
Adding upstream version 3.0.43.upstream/3.0.43upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/test_memory_leaks.py')
-rw-r--r--tests/test_memory_leaks.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/test_memory_leaks.py b/tests/test_memory_leaks.py
new file mode 100644
index 0000000..31ea7c8
--- /dev/null
+++ b/tests/test_memory_leaks.py
@@ -0,0 +1,35 @@
+from __future__ import annotations
+
+import gc
+
+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)])
+
+
+# Fails in GitHub CI, probably due to GC differences.
+@pytest.mark.xfail(reason="Memory leak testing fails in GitHub CI.")
+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