Jason R. Coombs avatar Jason R. Coombs committed ce42185

Improve the test case to avoid spurious errors about already existing symlinks.

Comments (0)

Files changed (1)


     package_name = 'sample'
     def setUp(self):
-        if os.path.exists('sample-tagged'): shutil.rmtree('sample-tagged')
+        if os.path.exists(self.tagged):
+            shutil.rmtree(self.tagged)
+        if os.path.exists(self.package_name):
+            self.remove_symlink(self.package_name)
         self.orig_sys_path = sys.path[:]
         symlink = getattr(os, 'symlink', None) or self._symlink_win32
     # regression test for issue6727
         not hasattr(sys, 'getwindowsversion')
-        or sys.getwindowsversion() >= (6,0),
+        or sys.getwindowsversion() >= (6, 0),
         "Windows Vista or later required")
     def test_symlinked_dir_importable(self):
         # make sure sample can only be imported from the current directory.
         sys.path[:] = ['.']
         # and try to import the package
-        pkg = __import__(self.package_name)
+        __import__(self.package_name)
     def tearDown(self):
         # now cleanup
         if os.path.exists(self.package_name):
-            os.rmdir(self.package_name)
+            self.remove_symlink(self.package_name)
         if os.path.exists(self.tagged):
         sys.path[:] = self.orig_sys_path
+    @staticmethod
+    def remove_symlink(name):
+        # On Windows, to remove a directory symlink, one must use rmdir
+        try:
+            os.rmdir(name)
+        except OSError:
+            os.remove(name)
 def test_main(verbose=None):
     run_unittest(ImportTests, PycacheTests,
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.