[Zope-Coders] Re: [Zope-Checkins] CVS:
Zope/lib/python/DateTime/tests -testDateTime.py:1.12.6.3
Andreas Jung
andreas@andreas-jung.com
Thu, 17 Oct 2002 17:50:31 +0200
The tests in StructuredText use the following code...also not bad ;-)
package_dir = os.path.split(ST.__file__)[0]
regressions=os.path.join(package_dir, 'regressions')
-aj
--On Donnerstag, 17. Oktober 2002 11:33 -0400 "Fred L. Drake, Jr."
<fdrake@acm.org> wrote:
>
> 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
>
---------------------------------------------------------------------
- Andreas Jung http://www.andreas-jung.com -
- EMail: andreas at andreas-jung.com -
- "Life is too short to (re)write parsers" -
---------------------------------------------------------------------