Jeremy Kloth <jeremy.kloth+python-trac...@gmail.com> added the comment:
Since my buildbot has been infected with this bug, I took some time to hunt it out. It turns out that issue is caused by an internal import triggered by the open() function (at least on Windows). A recent change to the interpreter (commit 9e4994d) changed the order of internal imports wrt file encodings so the default encoding for text files triggers a walking of sys.path thus seeing an incomplete test tree. The reason being that the path for the test tree is added to sys.path prior to it being completely flushed out. In theory this should not be a problem due to mtimes, but it seems that the all the additions occur within the time resolution of the directory's mtime. A quick fix for how internal imports happen *now* is: @@ -81,7 +81,7 @@ class TestPkg(unittest.TestCase): if contents is None: os.mkdir(fullname) else: - f = open(fullname, "w") + f = open(fullname, "w", encoding="utf-8") f.write(contents) if contents and contents[-1] != '\n': f.write('\n') however, to prevent further changes to internal imports cauing further problems, the following seems to be prudent: @@ -70,7 +70,6 @@ class TestPkg(unittest.TestCase): def mkhier(self, descr): root = tempfile.mkdtemp() - sys.path.insert(0, root) if not os.path.isdir(root): os.mkdir(root) for name, contents in descr: @@ -86,6 +85,7 @@ class TestPkg(unittest.TestCase): if contents and contents[-1] != '\n': f.write('\n') f.close() + sys.path.insert(0, root) self.root = root # package name is the name of the first item self.pkgname = descr[0][0] ---------- nosy: +jkloth _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue34200> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com