[Tutor] problems with doctest: apparent interferance between
kent37 at tds.net
Sun Apr 10 21:11:12 CEST 2005
As John Ridley suggests, you have to balance creation and deletion of Wall_clock instances. But
unfortunately del wc does not necessarily call Wall_clock.__del__() immediately.
See below for more...
Brian van den Broek wrote:
> def check_point(self, check_point_name = None):
> '''Creates a new _Check_point instance; appends it to .data.
> >>> # print "Testing check_point (intentional fail)."
> >>> print Wall_clock.is_instanced
> >>> # Why should it be True at this point?
> >>> # Note, too, that any of the commented changes
> >>> # make the most recent test fail!
> >>> wclock = Wall_clock() # Failing test WHY?
> >>> del(wclock)
> >>> new_wclock = Wall_clock() # This passes
You need a matching del new_wclock() here.
> def interval(self, interval_name = None):
> >>> # print "Testing interval (intentional fail)."
> >>> wc = Wall_clock()
> >>> del(wc)
> >>> wclock = Wall_clock()
> >>> # If I omit the rest of the tests here, no failure
> >>> # of the test of interest in Wall_clock.check_point
> >>> an_interval = wclock.interval('F')
> >>> same_name = wclock.interval('F')
> Traceback (most recent call last):
You need a matching del wclock here. BUT it still doesn't work because __del__() doesn't get called.
If you read the Note under the description of __del__() on this page
it says that in the case of an exception, references are retained in the stack track object. I tried
the workarounds suggested with no luck. but taking out the line that causes the exception (and
adding the missing del) does in fact make the test work.
As far as doctests being independent, each doctest has it's own copy globals(). But your class has
its own internal state, this is not affected by globals(). Basically there are side-effects to the
use of your class; doctest can't account for them.
Personally I don't see any compelling reason why Wall_clock() should be a singleton. It could easily
be a module with global functions and global state, or you could allow clients to have multiple
instances to time different things.
More information about the Tutor