From 3083a3a4563f2a65788ec16b9309d32825cd8509 2013-10-29 16:15:57
From: Thomas Kluyver <takowl@gmail.com>
Date: 2013-10-29 16:15:57
Subject: [PATCH] Make sessions REST API test more robust.

Was seeing failures on Windows because it failed to delete the folder.

---

diff --git a/IPython/html/services/sessions/tests/test_sessions_api.py b/IPython/html/services/sessions/tests/test_sessions_api.py
index 363d68b..0d31fa7 100644
--- a/IPython/html/services/sessions/tests/test_sessions_api.py
+++ b/IPython/html/services/sessions/tests/test_sessions_api.py
@@ -1,5 +1,6 @@
 """Test the sessions web service API."""
 
+import errno
 import io
 import os
 import json
@@ -51,7 +52,12 @@ class SessionAPITest(NotebookTestBase):
     """Test the sessions web service API"""
     def setUp(self):
         nbdir = self.notebook_dir.name
-        os.mkdir(pjoin(nbdir, 'foo'))
+        try:
+            os.mkdir(pjoin(nbdir, 'foo'))
+        except OSError as e:
+            # Deleting the folder in an earlier test may have failed
+            if e.errno != errno.EEXIST:
+                raise
 
         with io.open(pjoin(nbdir, 'foo', 'nb1.ipynb'), 'w') as f:
             nb = new_notebook(name='nb1')
@@ -62,7 +68,8 @@ class SessionAPITest(NotebookTestBase):
     def tearDown(self):
         for session in self.sess_api.list().json():
             self.sess_api.delete(session['id'])
-        shutil.rmtree(pjoin(self.notebook_dir.name, 'foo'))
+        shutil.rmtree(pjoin(self.notebook_dir.name, 'foo'),
+                      ignore_errors=True)
 
     def test_create(self):
         sessions = self.sess_api.list().json()