unit testing - Python Singletons - How do you get rid of (__del__) them in your testbench? -


Thanks a lot for the advice you gave me, using TestBench is a platform that has really shown me light And for this I am commendable. My problem is that I am playing with a singleton and generally I will not give it, but in a testbank I will need it, so how can anyone show me this thing? I have started with one and have made it in a testbank so that I can see what is going on. Now I do not know how to get rid of it!

Many thanks!

  unify import siz import logging import LOGLEVEL = logging.DEBUG class singleton: "" "a dragon singleton" "class __impl:" "" singleton implementation of interface "" def __int_ ( Self): self.log = logging.getLogger (__instance = None def __init __ (self) for the context of self.log.debug ("init% s"% self example: "" "Create Singleton Example" "Healthy" : "" "ID" "# Check whether we already have an example if the singleton .__ example is none: # Make Example and Remember Example Singleton __Example = Singleton.__pr () # Specify the Strolled instance only as a member in the handle .__ dict __ ['_ Singleton__instance'] = Singleton .__ Example def __getattr __ (self, et r ") : "" Provide access to implementation "" Return gaterate (self .__ example, atr) def __setattr __ (self, atrir, value): "Appoint delegation for implementation" "" return setter (self. Example, atr, value) class A: def __int __ (self): self.log = logging.getLogger () Self.log.debug ("init% s"% self.__ class __.__ name__) self.lowclass = singleton () self.id = self.lowclass.id () self.log.debug ("id: % S "% self.id) Category B: def __init __ (self): self.log = logging.getLogger () self.log.debug (" Init% S "% self .__ class__________ _ Lowclass = singleton () self.id = self.lowclass.id () self.log.debug ("id:% s"% self.id) class iris testcase): def testOne: a = A () help = A.id b = B () bid = b.id self.assertEqual (a.id, b.id) # # How can I destroy it? ? #Del A DEL B A1 = A () a1id = a1.id self. Asset not avalable (A1 ID, ADID) if __name__ == '__main__': # is a basic logger logging set. BasicConfig (format = "% (asctime) s% (Levelname) -8 s% (module) s% (funcName) s% (message) s, datefmt ="% H:% M:% S ", stream = sys .stderr) log = logging.gatlogger ("") logs .Setelval (Lovellviel) # suite = unittest.TestLoader (). LoadTestFormatCase (Estes) sys.exit (unittest.TextTestRunner (Verbosity = Lovellweel) .Run (Suite))  

You can enter in your test suite, To support the Tyrardown , a "drop everything" method must be added, giving the name of such method with the same major underscore , It tells the rest of the sw to leave alone, but the test is abnormal animal and often need to mess with such other intrinsic properties.

Therefore, for your specific case,

  class singleton: ... def _drop (self): "Skip the example (for testing purposes)." Similarly, for Borg, a  _drop  can release the method and clear the shared word and change it with a new brand. [9] Singleton .__ Example = A Dell Self. Sington__ instance  

.


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -