[Zope-Coders] If 'import Zope' is bad then...

Tres Seaver tseaver@zope.com
Wed, 23 Jan 2002 18:36:08 -0500


Shane Hathaway wrote:

> Evan Simpson wrote:
> 
>> Shane Hathaway wrote:
>>
>>> Well, it's becoming apparent that unit tests for a lot of Zope products
>>> really need to use "import Zope".  The CMF tests need to be cleaned up,
>>> but you may find that not all dependencies on the Zope package and
>>> products can be removed without major surgery. :-(
>>
>>
>> I strongly believe that 'import Zope' or equivalent should be usable 
>> from unit tests.    The environmental changes it makes (for example, 
>> Products.__path__ surgery, Products initialization, and HOME setup) 
>> should be shared code.  Packages that are separable from Zope, such as 
>> ZPT, would be able to use 'sys.modules.has_key' to detect when they 
>> are imported in a Zope context.
> 
> 
> 
> That would make sense for functional tests and system tests.  But as I 
> understand it, unit tests are not supposed to require a full application 
> environment.
> 
> I found a pretty good description of different kinds of tests here:
> 
> http://www.dotcomfidence.com/htmls/Knowledge_base/Testing.html
> 
> The things we are putting in the "tests" directories are actually of 
> various types, although we are using the unit testing framework for all 
> of them.
> 
> Fortunately, as of a few days ago, you can now safely "import Zope", but 
> when you do so, you are probably writing a test that is not a unit test. 
>  Tests that work on their own have extra value.  (For one thing, they 
> are faster. :-) )


The only side effect of 'import Zope' which makes sense to have
unit tests depend on is the "splice together INSTANCE_HOME/Products
and SOFTWARE_HOME/Products'.  I don't think it is possible to run
unit tests for products installed in the INSTANCE_HOME otherwise.


Tres.
-- 
===============================================================
Tres Seaver                                tseaver@zope.com
Zope Corporation      "Zope Dealers"       http://www.zope.com