[Pyunit-interest] Feature Request: Cleanup Registry
Brought to you by:
purcell
From: Jim F. <ji...@zo...> - 2002-07-08 18:28:09
|
Problem the Zope 3 project is making extensive use of PyUnit. Zope 3 unit tests often have to register components with various component registries. These registrations need to be torn down after each test. This became very tedious. For this reason, we've implemented a cleanup registry. Any stateful global objects, like component registries register functions with this cleanup registry. Test classes provide tearDown methods that call a method on the cleanup registry, which calls all the registered functions. This is an extremely useful pattern that might be beneficial to other projects. Further, it would be nice if test classes didn't have to provide a tear-down method that just called the cleanup registry (or mix-in a class that provided such a tearDown. Proposal Add a cleanup registry to the unittest module. The unittest module would provide an additional function, addCleanUp, which takes a callable object to be called without arguments after running each unit test. After each test, and after running the test class's tearDown method, each registered cleanup callable will be called. Suppose there was an application module with a global dictionary that was manipulated by application routines: TheData = {} The module would register the clear method of this dictionary with unittest.addCleanUp to make sure the dictionary was reinitialized after each test: import unittest unittest.addCleanUp(TheData.clear) I'd be happy to provide a patch. Jim -- Jim Fulton mailto:ji...@zo... Python Powered! CTO (888) 344-4332 http://www.python.org Zope Corporation http://www.zope.com http://www.zope.org |