New submission from STINNER Victor:

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__
        try:
            m.__file__ = os.path.abspath(m.__file__)
        except (AttributeError, OSError):
            pass
        try:
            m.__cached__ = os.path.abspath(m.__cached__)
        except (AttributeError, OSError):
            pass

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.

----------
files: libregrtest_module_path.patch
keywords: patch
messages: 261562
nosy: brett.cannon, haypo
priority: normal
severity: normal
status: open
title: regrtest: setup_tests() must not replace module.__path__ 
(_NamespacePath) with a simple list // importlib & abspath
versions: Python 3.6
Added file: http://bugs.python.org/file42130/libregrtest_module_path.patch

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue26538>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to