我需要在 Python (2.7) 中实现单例模式并使用单元测试覆盖代码。
下面是我使用的代码:
class Singleton(object):
def __new__(cls):
if not hasattr(cls, 'instance'):
cls.instance = super(Singleton, cls).__new__(cls)
return cls.instance
Run Code Online (Sandbox Code Playgroud)
为了使单元测试独立,我需要为此类实现一个析构函数。如何才能做到这一点?