diff -r 18a311479e8b Lib/distutils/file_util.py --- a/Lib/distutils/file_util.py Mon Aug 11 01:11:27 2014 +0200 +++ b/Lib/distutils/file_util.py Mon Aug 11 15:44:31 2014 +0300 @@ -194,7 +194,7 @@ try: os.rename(src, dst) except OSError as e: - (num, msg) = e + (num, msg) = e.args if num == errno.EXDEV: copy_it = True else: @@ -206,7 +206,7 @@ try: os.unlink(src) except OSError as e: - (num, msg) = e + (num, msg) = e.args try: os.unlink(dst) except OSError: diff -r 18a311479e8b Lib/distutils/tests/test_file_util.py --- a/Lib/distutils/tests/test_file_util.py Mon Aug 11 01:11:27 2014 +0200 +++ b/Lib/distutils/tests/test_file_util.py Mon Aug 11 15:44:31 2014 +0300 @@ -2,10 +2,13 @@ import unittest import os import shutil +import errno +from unittest.mock import patch from distutils.file_util import move_file from distutils import log from distutils.tests import support +from distutils.errors import DistutilsFileError from test.support import run_unittest class FileUtilTestCase(support.TempdirManager, unittest.TestCase): @@ -58,6 +61,26 @@ wanted = ['moving %s -> %s' % (self.source, self.target_dir)] self.assertEqual(self._logs, wanted) + @patch('os.rename', side_effect=OSError('wrong', 1)) + def test_exception_unpacking(self, _): + # When an OSError was raised inside the function, + # the exception was unpacked using ``(num, msg) = e``, + # which is wrong. + with self.assertRaises(DistutilsFileError): + with open(self.source, 'w') as stream: + pass + move_file(self.source, self.target, verbose=0) + + @patch('os.rename', side_effect=OSError(errno.EXDEV, 'wrong')) + @patch('os.unlink', side_effect=OSError('wrong', 1)) + def test_exception_unpacking(self, rename, unlink): + # When an OSError was raised inside the function, + # the exception was unpacked using ``(num, msg) = e``, + # which is wrong. + with self.assertRaises(DistutilsFileError): + with open(self.source, 'w') as stream: + pass + move_file(self.source, self.target, verbose=0) def test_suite(): return unittest.makeSuite(FileUtilTestCase)