Fix bug "AttributeError: 'generator' object has no attribute 'next'"

1. the bug:
   Captured traceback:
   ~~~~~~~~~~~~~~~~~~~
	Traceback (most recent call last):

	File "/opt/stack/freezer/freezer/tests/unit/scheduler/test_utils.py", line 53, in test_find_config_files_path
	ret = utils.find_config_files(temp_path)

	File "/opt/stack/freezer/freezer/scheduler/utils.py", line 53, in find_config_files
	for fname in os.walk(expanded_path).next()[2]:

	AttributeError: 'generator' object has no attribute 'next'

2. fix:
To get iterobject next element  is  changed to next(iterobject,defalt) in python3.x.

Change-Id: I558bbfecb4a9670a10b1fc649821d88619b7917c
This commit is contained in:
Caihui 2020-06-30 01:58:27 -07:00
parent 7236b3225e
commit 19aae78daf
2 changed files with 3 additions and 3 deletions

View File

@ -50,7 +50,7 @@ def find_config_files(path):
return [expanded_path]
file_list = []
if os.path.isdir(expanded_path):
for fname in os.walk(expanded_path).next()[2]:
for fname in next(os.walk(expanded_path))[2]:
if CONFIG_FILE_EXT.upper() == os.path.splitext(fname)[1].upper():
file_list.append('{0}/{1}'.format(expanded_path, fname))
return file_list

View File

@ -44,8 +44,8 @@ class TestUtils(unittest.TestCase):
temp.close()
self.assertFalse(os.path.exists(temp.name))
@unittest.skipIf(sys.version_info.major == 3,
'Not supported on python v 3.x')
# @unittest.skipIf(sys.version_info.major == 3,
# 'Not supported on python v 3.x')
def test_find_config_files_path(self):
temp = tempfile.NamedTemporaryFile('wb', delete=True,
suffix='.conf')