diff --git a/pytest-embedded/pytest_embedded/plugin.py b/pytest-embedded/pytest_embedded/plugin.py index 5fba0f5a..f87a12ff 100644 --- a/pytest-embedded/pytest_embedded/plugin.py +++ b/pytest-embedded/pytest_embedded/plugin.py @@ -2,6 +2,7 @@ import datetime import dbm import functools +import gc import importlib import io import logging @@ -409,6 +410,17 @@ def _close_or_terminate(obj): return try: + referrers = gc.get_referrers(obj) + for _referrer in referrers: + if isinstance(_referrer, list): + for _i, val in enumerate(_referrer): + if val is obj: + _referrer[_i] = None + elif isinstance(_referrer, dict): + for key, value in _referrer.items(): + if value is obj: + _referrer[key] = None + if isinstance(obj, (subprocess.Popen, multiprocessing.process.BaseProcess)): obj.terminate() obj.kill()