Re-running unittest

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Mon Jul 23 21:36:14 EDT 2007


At 23/07/2007 09:59, "Israel Fernández Cabrera" <iferca at gmail.com> wrote:

(Please keep posting on the list - many other people may have better ideas  
on this)

> Well... probably my English and my intentions to not ti write
> to much made my explanation unclear. The code I wrote was just
> to illustrate my problem, is not the "real" code. Your
> assumptions were OK, I?m loading the test inside and IDE, but
> not IDLE. What I want to to is to "discover" the tests, and
> then provide a GUI to execute them easily, like Eclipse does.
> As you say, I get test objects and code objects created that is
> why I use reload to "refresh" the module object. My concern is
> that in the sample code, all the Unittest related objects are
> recreated and the objects are loaded from a string before
> executing the tests, but still they remain in memory.
> I have used "reload" just to prove the problem could be fixed
> like that, to confirm the source of the problem, I agree this
> is not a good solution.
> The fixing test looks strange but was the easier way I found to
> reproduce the problem since the test does not actually "test"
> any outside object, was just a way to change the passing/no
> passing status of the test.
> Thks for your time hope this time I made myself clear ;)

I think you can't use reload in this scenario. Your framework would have  
to know which modules to reload, which names to rebind, which imports to  
re-execute, which objects to re-create... Reloading without intimate  
knowledge of how the reloaded module is used is hard, if not impossible.
Perhaps the best option is to run the tests in another process. Use any of  
the available IPC mechanisms to gather the test results. This has the  
added advantage of isolating the tested code from your GUI testing  
framework; all requested resources are released to the OS; the tests run  
in a predictable environment; etc.




More information about the Python-list mailing list