@@ -94,7 +94,7 @@ def onerror(func, path, exc_info):
9494 func (path ) # Will scream if still not possible to delete.
9595 except Exception as ex :
9696 if HIDE_WINDOWS_KNOWN_ERRORS :
97- raise SkipTest ("FIXME: fails with: PermissionError\n {}" .format (ex ))
97+ raise SkipTest ("FIXME: fails with: PermissionError\n {}" .format (ex )) from ex
9898 raise
9999
100100 return shutil .rmtree (path , False , onerror )
@@ -746,7 +746,7 @@ def _obtain_lock_or_raise(self):
746746 fd = os .open (lock_file , flags , 0 )
747747 os .close (fd )
748748 except OSError as e :
749- raise IOError (str (e ))
749+ raise IOError (str (e )) from e
750750
751751 self ._owns_lock = True
752752
@@ -801,19 +801,19 @@ def _obtain_lock(self):
801801 while True :
802802 try :
803803 super (BlockingLockFile , self )._obtain_lock ()
804- except IOError :
804+ except IOError as e :
805805 # synity check: if the directory leading to the lockfile is not
806806 # readable anymore, raise an exception
807807 curtime = time .time ()
808808 if not osp .isdir (osp .dirname (self ._lock_file_path ())):
809809 msg = "Directory containing the lockfile %r was not readable anymore after waiting %g seconds" % (
810810 self ._lock_file_path (), curtime - starttime )
811- raise IOError (msg )
811+ raise IOError (msg ) from e
812812 # END handle missing directory
813813
814814 if curtime >= maxtime :
815815 msg = "Waited %g seconds for lock at %r" % (maxtime - starttime , self ._lock_file_path ())
816- raise IOError (msg )
816+ raise IOError (msg ) from e
817817 # END abort if we wait too long
818818 time .sleep (self ._check_interval )
819819 else :
@@ -878,8 +878,8 @@ def __getitem__(self, index):
878878
879879 try :
880880 return getattr (self , index )
881- except AttributeError :
882- raise IndexError ("No item found with id %r" % (self ._prefix + index ))
881+ except AttributeError as e :
882+ raise IndexError ("No item found with id %r" % (self ._prefix + index )) from e
883883 # END handle getattr
884884
885885 def __delitem__ (self , index ):
0 commit comments