[Python-Dev] test_import failing

Guido van Rossum guido@python.org
Tue, 10 Oct 2000 08:04:39 -0500


> Neil Schemenauer writes:
>  > I assume the CVS sources are basicly the same as 2.0c1.  Anyhow,
>  > test_import is failing on my Debian machine.  The script is
>  > creating "@test.py" and then trying to import it.  "." is not in
>  > sys.path for some reason.
> 
>   Jeremy & I finally figured this out.  "make test" runs python with
> PYTHONPATH set to '' (an empty string).  This is decidedly different
> from running with PYTHONPATH unset (I consider this a bug that should
> be fixed in 2.1).
>   The empty string is interpreted as the current directory (as
> expected), so running "make test" adds the current directory to
> sys.path, but running the regression test (test_import or regrtest) as
> a script does not.
>   We decided not to fix this now, since it's too late to be sure it's
> the right change, and adjusting the test case also means a very late
> change.  So whoever runs the tests is responsible for making sure the
> current directory is on sys.path.  (*Really* bogus!)

Proper fix, which I will check in momentarily: put

    import sys
    sys.path.insert(0, os.curdir)

in front of test_import.py; and add

    del sys.path[0]

to the end.

--Guido van Rossum (home page: http://www.python.org/~guido/)