[Zope-Coders] Re: [Zope-Checkins] CVS: Zope/lib/python/DateTime/tests -testDateTime.py:1.12.6.3

Fred L. Drake, Jr. fdrake@acm.org
Thu, 17 Oct 2002 11:33:24 -0400


Andreas Jung writes:
 > Isn't __file__ only defined when a module is imported but
 > undefined when the file is run directly from the Python

That's correct.

 > interpreter. I agreee that there should be some more logic if
 > you run the unittest on your own. But isn't the suggested
 > way to run the tests through the testrunner?

That's the suggested way, but it should be easy to run the tests
individually as well.  I've modified the test module on the trunk and
2.6 branch to work both ways, and Shane immediately suggested a
simpler way to do it:

----------------------------------------------------
import os.path
import sys

try:
    __file__
except NameError:
    __file__ = sys.argv[0]

DATADIR = os.path.dirname(os.path.abspath(__file__))
----------------------------------------------------


  -Fred

-- 
Fred L. Drake, Jr.  <fdrake at acm.org>
PythonLabs at Zope Corporation