Author jkloth
Recipients LorenzMende, barry, brett.cannon, jkloth, ncoghlan, v2m, vstinner
Date 2018-09-02.14:19:16
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1535897956.66.0.56676864532.issue34200@psf.upfronthosting.co.za>
In-reply-to
Content
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]
History
Date User Action Args
2018-09-02 14:19:16jklothsetrecipients: + jkloth, barry, brett.cannon, ncoghlan, vstinner, LorenzMende, v2m
2018-09-02 14:19:16jklothsetmessageid: <1535897956.66.0.56676864532.issue34200@psf.upfronthosting.co.za>
2018-09-02 14:19:16jklothlinkissue34200 messages
2018-09-02 14:19:16jklothcreate