python/tests/utils.py: try reopening the file is deleting it fails on windows
authorPaul Brossier <piem@piem.org>
Mon, 16 May 2016 04:09:38 +0000 (06:09 +0200)
committerPaul Brossier <piem@piem.org>
Mon, 16 May 2016 04:09:38 +0000 (06:09 +0200)
python/tests/utils.py

index 4e4ac71..2e3c31e 100644 (file)
@@ -29,7 +29,16 @@ def get_tmp_sink_path():
     return path
 
 def del_tmp_sink_path(path):
-    os.unlink(path)
+    try:
+        os.unlink(path)
+    except WindowsError as e:
+        print("deleting {:s} failed ({:s}), reopening".format(path, repr(e)))
+        with open(path, 'wb') as f:
+            f.close()
+        try:
+            os.unlink(path)
+        except WindowsError as f:
+            print("deleting {:s} failed ({:s}), aborting".format(path, repr(e)))
 
 def array_from_yaml_file(filename):
     import yaml