i need implement singleton pattern in python (2.7) , cover code unit tests.
below code use:
class singleton(object): def __new__(cls): if not hasattr(cls, 'instance'): cls.instance = super(singleton, cls).__new__(cls) return cls.instance for unit tests independent, need implement destructor class. how can done?
you can delete instance attribute:
del singleton.instance if subclassing this, make class method:
@classmethod def clear_instance(cls): del cls.instance
Comments
Post a Comment