[Python-Dev] Tests failing on Windows with TESTFN

Jeremy Kloth jeremy.kloth at gmail.com
Sun Jul 29 11:40:45 EDT 2018


On Sun, Jul 29, 2018 at 9:34 AM Tim Golden <mail at timgolden.me.uk> wrote:
> For test_mailbox I've experimentally implemented a hybrid tempfile /
> local directory solution. ie I've created a new file on each run, but
> only within the python_<pid> folder which already exists. As long as the
> directory cleans up there should be no leftovers. That's certainly
> helped although my re-run harness has provoked at least one error.

As Eryk noted, the fix for mailbox.py (yes, the stdlib needs fixing in
this case) is quite simple:

diff --git a/Lib/mailbox.py b/Lib/mailbox.py
index 056251d..eb85df1 100644
--- a/Lib/mailbox.py
+++ b/Lib/mailbox.py
@@ -701,8 +701,7 @@ class _singlefileMailbox(Mailbox):
         try:
             os.rename(new_file.name, self._path)
         except FileExistsError:
-            os.remove(self._path)
-            os.rename(new_file.name, self._path)
+            os.replace(new_file.name, self._path)
         self._file = open(self._path, 'rb+')
         self._toc = new_toc
         self._pending = False

-- 
Jeremy Kloth


More information about the Python-Dev mailing list