Author vstinner
Recipients brett.cannon, vstinner
Date 2016-03-11.11:44:27
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Extract of test.libregrtest.setup_tests():

    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__)

Because of this code, it's not possible to store test files outside Lib/test/. For the issue #26295 (test_regrtest), I would like to create a temporary directory and then a subdirectory test/ to create temporary test files.

Attached patch adds _NamespacePath.__setitem__() method and modify setup_tests() to keep the _NamespacePath type of module.__path__.

Maybe we should move this abspath() code somewhere in importlib. The site module already contains similar code, abs_paths() function:

    for m in set(sys.modules.values()):
        if (getattr(getattr(m, '__loader__', None), '__module__', None) not in
                ('_frozen_importlib', '_frozen_importlib_external')):
            continue   # don't mess with a PEP 302-supplied __file__
            m.__file__ = os.path.abspath(m.__file__)
        except (AttributeError, OSError):
            m.__cached__ = os.path.abspath(m.__cached__)
        except (AttributeError, OSError):

Since this code looks to depend on the implementation of importlib (the __loader__ test), IMHO it makes sense to move the code directly somewhere in importlib.
Date User Action Args
2016-03-11 11:44:27vstinnersetrecipients: + vstinner, brett.cannon
2016-03-11 11:44:27vstinnersetmessageid: <>
2016-03-11 11:44:27vstinnerlinkissue26538 messages
2016-03-11 11:44:27vstinnercreate