[Python-Dev] file is not always an absolute path (original) (raw)

Ezio Melotti ezio.melotti at gmail.com
Sat Feb 6 21:49:05 CET 2010


In #7712 I was trying to change regrtest to always run the tests in a temporary CWD (e.g. /tmp/@test_1234_cwd/). The patches attached to the issue add a context manager that changes the CWD, and it works fine when I run ./python -m test.regrtest from trunk/. However, when I try from trunk/Lib/ it fails with ImportErrors (note that the latest patch by Florent Xicluna already tries to workaround the problem). The traceback points to "the_package = import(abstest, globals(), locals(), [])" in runtest_inner (in regrtest.py), and a "print import('test').file" there returns 'test/init.pyc'. This can be reproduced quite easily:

trunk$ ./python Python 2.7a2+ (trunk:77941M, Feb 3 2010, 06:40:49) [GCC 4.4.1] on linux2 Type "help", "copyright", "credits" or "license" for more information.

import os, sys os.getcwd() '/home/wolf/dev/trunk' import test test.file # absolute '/home/wolf/dev/trunk/Lib/test/init.pyc' os.chdir('/tmp') test.file '/home/wolf/dev/trunk/Lib/test/init.pyc' from test import test_unicode # works test_unicode.file '/home/wolf/dev/trunk/Lib/test/test_unicode.pyc'

[21]+ Stopped ./python

trunk$ cd Lib/ trunk/Lib$ ../python Python 2.7a2+ (trunk:77941M, Feb 3 2010, 06:40:49) [GCC 4.4.1] on linux2 Type "help", "copyright", "credits" or "license" for more information.

import os, sys os.getcwd() '/home/wolf/dev/trunk/Lib' import test test.file # relative 'test/init.pyc' os.chdir('/tmp') from test import test_unicode # fails Traceback (most recent call last): File "", line 1, in ImportError: cannot import name test_unicode

Is there a reason why in the second case test.file is relative?



More information about the Python-Dev mailing list