Message261587
Longer extract of setup_tests(), with the long comment:
# Some times __path__ and __file__ are not absolute (e.g. while running from
# Lib/) and, if we change the CWD to run the tests in a temporary dir, some
# imports might fail. This affects only the modules imported before os.chdir().
# These modules are searched first in sys.path[0] (so '' -- the CWD) and if
# they are found in the CWD their __file__ and __path__ will be relative (this
# happens before the chdir). All the modules imported after the chdir, are
# not found in the CWD, and since the other paths in sys.path[1:] are absolute
# (site.py absolutize them), the __file__ and __path__ will be absolute too.
# Therefore it is necessary to absolutize manually the __file__ and __path__ of
# the packages to prevent later imports to fail when the CWD is different.
for module in sys.modules.values():
if hasattr(module, '__path__'):
module.__path__ = [os.path.abspath(path)
for path in module.__path__]
if hasattr(module, '__file__'):
module.__file__ = os.path.abspath(module.__file__) |
|
| Date |
User |
Action |
Args |
| 2016-03-11 17:55:49 | vstinner | set | recipients:
+ vstinner, brett.cannon, eric.smith |
| 2016-03-11 17:55:49 | vstinner | set | messageid: <1457718949.9.0.00956203082873.issue26538@psf.upfronthosting.co.za> |
| 2016-03-11 17:55:49 | vstinner | link | issue26538 messages |
| 2016-03-11 17:55:49 | vstinner | create | |
|