Однако я бы хотел, чтобы программа пропускала строку, если выполняется определенное условие.
У меня есть XML-файл, в котором есть значение, определяющее тип запуска. В коде Python я написал блок If/Else для преобразования значения в число (см. ниже)
Код: Выделить всё
# If / Else to convert test_run_type text to a value
if test_run_type == "Regression":
test_run_type_value = '1'
elif test_run_type == "Smoke":
test_run_type_value = '2'
elif test_run_type == "Sanity":
test_run_type_value = '3'
Код: Выделить всё
# Open Test Scenario Workbook; Instantiate worksheet object
wb = xlrd.open_workbook(os.path.join(test_case_directory, Product + '.xlsx'))
sh = wb.sheet_by_index(0)
## Begin For Loop to iterate through Test Scenarios
i = 1
rows = sh.nrows
empty_cell = False
for x in range(1, sh.nrows):
cell_val = sh.cell(i, 0).value
if cell_val == '':
# If Cell Value is empty, set empty_cell to True
empty_cell = True
else:
# If Cell Value is NOT empty, set empty_cell to False
empty_cell = False
regression_check = sh.cell_value(i, 3)
smoke_check = sh.cell_value(i, 4)
sanity_check = sh.cell_value(i, 5)
# If / Else Section to check if a test needs to be run
#### Program is running ALL rows & NOT skipping rows
if test_run_type_value == 3 and sanity_check == "False":
continue
else:
pass
if test_run_type_value == 2 and smoke_check == "False":
continue
else:
pass
if test_run_type_value == 1 and regression_check == "False":
continue
else:
pass
- test_run_type_value равно «3», а sanity_check равно False
- test_run_type_value равно «2», а Smoke_check равно False
- test_run_type_value равно «1», а reгрессия_check равно False
Я сделал снимок экрана листа Excel.
введите здесь описание изображения
Судя по таблице (см. прикрепленное изображение), программа должна пропустить первую строку, если значение test_run_type_value равно «3», но это не так. Программа перебирает все строки (даже если значение test_run_type_value равно 1, 2 или 3)
Заранее спасибо
Кен
Подробнее здесь: https://stackoverflow.com/questions/454 ... on-is-true