]> granicus.if.org Git - python/commitdiff
support: add more info on temp_dir() and change_cwd() failure
authorVictor Stinner <victor.stinner@gmail.com>
Wed, 8 Feb 2017 11:25:00 +0000 (12:25 +0100)
committerVictor Stinner <victor.stinner@gmail.com>
Wed, 8 Feb 2017 11:25:00 +0000 (12:25 +0100)
Log the OSError exception message.

Lib/test/support/__init__.py

index 345e16d7541732a51d46bd0f60dd6069b03301ed..58e4f92ead196042397e37f90ec01514a3117c8a 100644 (file)
@@ -954,10 +954,11 @@ def temp_dir(path=None, quiet=False):
         try:
             os.mkdir(path)
             dir_created = True
-        except OSError:
+        except OSError as exc:
             if not quiet:
                 raise
-            warnings.warn('tests may fail, unable to create temp dir: ' + path,
+            warnings.warn(f'tests may fail, unable to create '
+                          f'temporary directory {path}: {exc}',
                           RuntimeWarning, stacklevel=3)
     try:
         yield path
@@ -981,10 +982,11 @@ def change_cwd(path, quiet=False):
     saved_dir = os.getcwd()
     try:
         os.chdir(path)
-    except OSError:
+    except OSError as exc:
         if not quiet:
             raise
-        warnings.warn('tests may fail, unable to change CWD to: ' + path,
+        warnings.warn(f'tests may fail, unable to change current working '
+                      f'directory to {path}: {exc}',
                       RuntimeWarning, stacklevel=3)
     try:
         yield os.getcwd()