[Zope-Coders] If 'import Zope' is bad then...
Shane Hathaway
shane@zope.com
Wed, 23 Jan 2002 12:45:51 -0500
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. :-) )
Shane