add test for warning

This commit is contained in:
Talley Lambert
2024-06-03 10:06:22 -04:00
parent 0585197383
commit 4badc90425
2 changed files with 10 additions and 0 deletions

View File

@@ -29,6 +29,7 @@ SOFTWARE.
from __future__ import annotations
import warnings
from concurrent.futures import Future
from contextlib import suppress
from enum import IntFlag, auto
@@ -223,6 +224,9 @@ def _weak_func(func: Callable[P, R]) -> Callable[P, R]:
def weak_func(*args, **kwargs):
if method := weak_method():
return method(*args, **kwargs)
warnings.warn(
"Method has been garbage collected", RuntimeWarning, stacklevel=2
)
return weak_func

View File

@@ -226,6 +226,12 @@ def test_qthrottled_does_not_prevent_gc(qtbot):
qtbot.waitUntil(thing.tmethod._future.done, timeout=2000)
assert mock.call_count == 2
wm = thing.tmethod
assert isinstance(wm, ThrottledCallable)
del thing
gc.collect()
assert thing_ref() is None
with pytest.warns(RuntimeWarning, match="Method has been garbage collected"):
wm()
wm._set_future_result()