[Zope-Coders] sys futzing
Tres Seaver
tseaver@zope.com
Sun, 18 Nov 2001 08:42:49 -0500
Chris Withers wrote:
> Chris McDonough wrote:
>
>>if __name__=='__main__':
>> import sys
>> sys.path.insert(0, '../../..')
>> sys.path.insert(0, '..')
>>
>
> I thought doing things like this were frowned upon now?
>
> Is the policy on this anywhere documented yet?
Note the condition: 'sys.path' only gets munged if that
module is run as a script, e.g.::
$ cd lib/python/Products/FooProduct/tests
$ python checkSomeGnarlyFeature.py
For "regression tests", like the multithread tests ChrisM
put in a separate module yesterday, assuming that the test
will be run directly from the command line is fine.
If, however, the test is a unit test, then the second path
insertion is likely to mean that test will fail when run via
'testrunner', as the parent package won't be in the path
at that point. In such a case, the appropriate fix is to
do imports from fully-qualified package/module names.
BTW, what module was that in? I don't see that usage in any
of ChrisM's recent checkins.
Tres.
--
===============================================================
Tres Seaver tseaver@zope.com
Zope Corporation "Zope Dealers" http://www.zope.com