[Python-Dev] Re: [Python-checkins] python/dist/src/Lib/email/test test_email_codecs.py,1.1,1.2

Barry A. Warsaw barry@zope.com
Mon, 22 Jul 2002 15:38:16 -0400


>>>>> "TP" == Tim Peters <tim.one@comcast.net> writes:

    TP> Note test/README, which says in part:

    TP> """
    TP> NOTE:  Always import something from test_support like so:

    TP>     from test_support import verbose

    TP> or like so:

    |     import test_support
    |     ... use test_support.verbose in the code ...

    TP> Never import anything from test_support like this:

    TP>     from test.test_support import verbose

    TP> "test" is a package already, so can refer to modules it
    TP> contains without "test." qualification.  If you do an explicit
    TP> "test.xxx" qualification, that can fool Python into believing
    TP> test.xxx is a module distinct from the xxx in the current
    TP> package, and you can end up importing two distinct copies of
    TP> xxx.  This is especially bad if xxx=test_support, as
    TP> regrtest.py can (and routinely does) overwrite its "verbose"
    TP> and "use_large_resources" attributes: if you get a second copy
    TP> of test_support loaded, it may not have the same values for
    TP> those as regrtest intended.  """

Yep, but I think those recommendations are out-of-date.  You added
them to the file almost 2 years ago. ;)

Note that the warnings in that README go away when regrtest also
imports test_support from the test package.

    TP> I don't have a deep understanding of these miserable issues,
    TP> so settled for a one-line patch that worked.  The admonition
    TP> to never import from test.test_support was a BDFL
    TP> Pronouncement at the time.

Hmm, I don't know if he considers that admonition to still be in
effect, but I'd like to hope not.  We're discouraging relative imports
these days, and I don't see any deep reason why the regression tests
need to break this rule to function (and indeed, on Unix at least
it doesn't seem to).

    TP> Note that Jack runs tests in ways nobody else does, via
    TP> importing something or other from an interactive Python
    TP> session (Mac Classic doesn't have a cmdline shell -- something
    TP> like that).  It's always an adventure trying to guess how
    TP> things will break for him, although I'm not sure your
    TP> suggestion is (or isn't) relevant to Jack.

I wouldn't presume to know!  So I'll generate a patch, upload it to
SF, and assign it to Jack for review.

    TP> I imagine things will work provided that all imports "are the
    TP> same".

Yes.
    
    TP> I'm not sure fiddling all the code is worth it just to
    TP> save a line of typing in the email package's test suite.

It's a bit uglier than that because since Lib/test gets magically
added to sys.path during regrtest by virtue of running "python
Lib/test/regrtest.py".  So to find the "same" test_support module,
you'd probably have to do something more along the lines of

>>> import os
>>> import test.regrtest
>>> testdir = os.path.dirname(test.regrtest.__file__)
>>> sys.path.insert(0, testdir)
>>> import test_support

blechi-ly y'rs,
-Barry