@@ -94,7 +94,7 @@ def onerror(func, path, exc_info):
9494func (path ) # Will scream if still not possible to delete.
9595except Exception as ex :
9696if 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
9898raise
9999
100100return shutil .rmtree (path , False , onerror )
@@ -746,7 +746,7 @@ def _obtain_lock_or_raise(self):
746746fd = os .open (lock_file , flags , 0 )
747747os .close (fd )
748748except OSError as e :
749- raise IOError (str (e ))
749+ raise IOError (str (e ))from e
750750
751751self ._owns_lock = True
752752
@@ -801,19 +801,19 @@ def _obtain_lock(self):
801801while True :
802802try :
803803super (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
807807curtime = time .time ()
808808if not osp .isdir (osp .dirname (self ._lock_file_path ())):
809809msg = "Directory containing the lockfile %r was not readable anymore after waiting %g seconds" % (
810810self ._lock_file_path (), curtime - starttime )
811- raise IOError (msg )
811+ raise IOError (msg )from e
812812# END handle missing directory
813813
814814if curtime >= maxtime :
815815msg = "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
818818time .sleep (self ._check_interval )
819819else :
@@ -878,8 +878,8 @@ def __getitem__(self, index):
878878
879879try :
880880return 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
885885def __delitem__ (self , index ):
0 commit comments