-
Notifications
You must be signed in to change notification settings - Fork 710
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Breaking change: - `Filter()` subclasses have to call `super()`.
- Loading branch information
1 parent
568de64
commit 7776bf9
Showing
3 changed files
with
89 additions
and
61 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
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
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 |