How do you register cleanup code to be run after script execution?

Dan Gass dmgass at hotmail.com
Tue May 11 09:48:59 EDT 2004


Upon reflection, this is close to what I want but not quite what I
need.

I wanted this answer to use in an open source test generator framework
I am writing to unit/integration/function test Python, C, or C++ (it
could be extended to other languages).  For now the user interface is
Python (someday maybe I'll make an XML interface).  The user writes a
script to setup the test and the framework generates the test and
executes it.

I wanted the generation of the test and the execution of it to occur
when the script is done running.  The trouble with using the atexit
mechanism is that it is uses a last in first executed.  I may run into
trouble with integration tests where other things get registered after
me and that cleanup will get done before I start (and they may shut
down resources the test needs to execute).  I'm thinking it maybe just
best to provide the user a function to generate/execute the test that
they must call last.

BTW, as part of this effort I required a much more powerful
configuration mechanism that is provided by the global module
ConfigParser. If you are interested in this area please see
http://config-py.sourceforge.net/.

Thanks for your responses,
Dan Gass



More information about the Python-list mailing list