diff -r d5536c06a082 Lib/importlib/_bootstrap.py --- a/Lib/importlib/_bootstrap.py Fri Jul 05 01:40:52 2013 +0200 +++ b/Lib/importlib/_bootstrap.py Mon Aug 12 13:56:21 2013 -0400 @@ -1299,7 +1299,7 @@ """ if path == '': - path = '.' + path = _os.getcwd() try: finder = sys.path_importer_cache[path] except KeyError: @@ -1370,7 +1370,7 @@ loaders.extend((suffix, loader) for suffix in suffixes) self._loaders = loaders # Base (directory) path - self.path = path or '.' + self.path = path or _os.getcwd() self._path_mtime = -1 self._path_cache = set() self._relaxed_path_cache = set() diff -r d5536c06a082 Lib/test/test_import.py --- a/Lib/test/test_import.py Fri Jul 05 01:40:52 2013 +0200 +++ b/Lib/test/test_import.py Mon Aug 12 13:56:21 2013 -0400 @@ -250,6 +250,22 @@ if TESTFN in sys.modules: del sys.modules[TESTFN] + def test_absolute_file_path(self): + # when module is imported from the cwd, ensure that + # module.__file__ is an absolute path + source = TESTFN + ".py" + with open(source, "w") as f: + f.write("test = None\n") + + try: + mod = __import__(TESTFN) + abs_path = os.path.abspath(mod.__file__) + self.assertEqual(mod.__file__, abs_path) + finally: + remove_files(TESTFN) + if TESTFN in sys.modules: + del sys.modules[TESTFN] + def test_import_name_binding(self): # import x.y.z binds x in the current namespace. import test as x diff -r d5536c06a082 Lib/test/test_importlib/import_/test_path.py --- a/Lib/test/test_importlib/import_/test_path.py Fri Jul 05 01:40:52 2013 +0200 +++ b/Lib/test/test_importlib/import_/test_path.py Mon Aug 12 13:56:21 2013 -0400 @@ -82,11 +82,11 @@ path = '' module = '' importer = util.mock_modules(module) - hook = import_util.mock_path_hook(os.curdir, importer=importer) + hook = import_util.mock_path_hook(os.getcwd(), importer=importer) with util.import_state(path=[path], path_hooks=[hook]): loader = machinery.PathFinder.find_module(module) self.assertIs(loader, importer) - self.assertIn(os.curdir, sys.path_importer_cache) + self.assertIn(os.getcwd(), sys.path_importer_cache) def test_None_on_sys_path(self): # Putting None in sys.path[0] caused an import regression from Python