test_arr = []
with open(fileName, 'r') as file:
    for line in file:
        if line.startswith('---') and 'section1' in line:
            break
for line in file:
    if '---' in line:
        break
fields1 = line.split(',')
for item in fields1:
    testarr.append({config.get('test', 'test'): item})
with open(test_dir, 'w') as test_file:
    json.dump(testarr, test_file)
Ошибка при циклическом просмотре текстового файла в python