[TIP] cleanUp for unittest

Michael Foord fuzzyman at voidspace.org.uk
Tue Apr 7 09:36:09 PDT 2009


Fred Drake wrote:
> On Tue, Apr 7, 2009 at 11:58 AM, Olemis Lang <olemis at gmail.com> wrote:
>   
>>> This relies on Python's garbage collector implementation details (i.e.
>>> refcounting),
>>>       
>> That's th idea ;)
>>     
>
> This seems to make it very easy to create fragile fixtures
> unintentionally, since not all Python implementations share the same
> garbage collection semantics.
>   

Yup. Tests that rely on deterministic finalisation break on IronPython, 
Jython and PyPy. We're going to start fixing the Python test suite to 
remove these kinds of problems.

In addition, cyclic references involving explicit finalizers won't be 
collected *at all* on CPython.

Michael Foord
>   
>> - As I said, the semantics for resource proxies is that they control
>> access to the underlying resource as long as they are loaded in
>> memory. If you want to discard'em call (force?) GC .
>>
>> - If you want to control shared access to your resources, then it is
>> very posible that you might want to use either GoF Singleton or
>> ParametricSingleton pattern to implement the proxy classes ( there is
>> actually an article in JOT about using ParametricSingleton to control
>> access to shared RMI registries ;)
>>     
>
> While this seems reasonable on the face of it, it really adds more
> complexity.  This is the result of needing more code to properly
> manage the resource allocation than what's needed just to tear it
> down.  Add to that the loss of determinism, and there's no real win
> that I can see.
>
> A simple stack of cleanup operations is just drop-dead simple, so is
> hard to beat.
>
>
>   -Fred
>
>   


-- 
http://www.ironpythoninaction.com/
http://www.voidspace.org.uk/blog





More information about the testing-in-python mailing list