Рекурсивно проверяйте согласованность каждого значения поля проекта/CR Id каждого тестового примера.Python

Программы на Python
Ответить Пред. темаСлед. тема
Anonymous
 Рекурсивно проверяйте согласованность каждого значения поля проекта/CR Id каждого тестового примера.

Сообщение Anonymous »

В Azure DevOps я пытаюсь рекурсивно получить значение поля проекта/CR Id из каждой пользовательской истории и всех ее дочерних элементов -> тестовые примеры на любом уровне и сопоставить значение поля проекта/CR Id каждого тестового примера для согласованности, если они присутствуют и одинаковы. При использовании SDK я получаю следующую ошибку.
import os
import operator as op
import re
from azure.devops.connection import Connection
from msrest.authentication import BasicAuthentication

# Replace with your actual PAT and organization URL
personal_access_token = 'PAT'
organization_url = 'https://dev.azure.com/**'
work_item_id = 123 # Replace with your actual work item ID

# Create connection to the organization
credentials = BasicAuthentication('', personal_access_token)
connection = Connection(base_url=organization_url, creds=credentials)

# Get work item tracking client for interacting with work items API.
work_item_tracking_client = connection.clients.get_work_item_tracking_client()

def check_project_cr_ids_consistency(work_item):
project_cr_ids_consistent = True
project_cr_id_value = None

def recursive_check(item):
nonlocal project_cr_ids_consistent, project_cr_id_value

if 'Custom.ProjectorCRId' in item.fields:
current_project_cr_id_value = item.fields['Custom.ProjectorCRId']

if current_project_cr_id_value.strip() == "":
project_cr_ids_consistent = False

elif project_cr_id_value is None:
project_cr_id_value = current_project_cr_id_value

elif project_cr_id_value != current_project_cr_id_value:
project_cr_ids_consistent = False

else:
project_cr_ids_consistent = False

if hasattr(item, 'relations'):
for relation in item.relations:
if relation.rel == 'System.LinkTypes.Hierarchy-Forward':
child_id = int(relation.url.split('/')[-1])
child_work_items = work_item_tracking_client.get_work_items(ids=[child_id])

for child_work_item in child_work_items:
recursive_check(child_work_item)

recursive_check(work_item)

return (project_cr_ids_consistent, project_cr_id_value)

try:
# Fetch details of the specific work item by ID, including relations (child items).
work_item = work_item_tracking_client.get_work_item(id=work_item_id, expand='all')

# Print details of the fetched work item.
title=work_item.fields['System.Title']
print(f"Title: {title}")

consistent , cr_or_project_value= check_project_cr_ids_consistency(work_item)

except Exception as e :
print(f"An error occurred: {e}")

print(f"Project/CR IDs Consistent: {consistent}")
if not consistent :
print("Inconsistent Project/CR IDs found among children.")
else :
print(f"Consistent Project/CR ID Value: {cr_or_project_value}")

pattern=re.compile(r'\b' + re.escape(cr_or_project_value) + r'\b')

match=pattern.search(title)

print(bool(match))

Ошибка:
An error occurred: 'NoneType' object is not iterable

Exception has occurred: NameError
name 'consistent' is not defined
File "C:\Users\Desktop\CRAutomation\projectid.py", line 67, in
print(f"Project/CR IDs Consistent: {consistent}")
NameError: name 'consistent' is not defined

Полная ошибка:-
PS C:\Users\Desktop\CRAutomation> c:; cd 'c:\Users\Desktop\repo\CR_Devops_Automate'; & 'c:\Python310\python.exe' 'c:\Users\703301396\.vscode\extensions\ms-python.debugpy-2024.10.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher' '55082' '--' 'C:\Users\703301396\Desktop\CRAutomation\projectid.py'

Title: test 123
An error occurred: 'NoneType' object is not iterable
Traceback (most recent call last):
File "c:\Python310\lib\runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "c:\Python310\lib\runpy.py", line 86, in _run_code
exec(code, run_globals)
File "c:\Users\.vscode\extensions\ms-python.debugpy-2024.10.0-win32-x64\bundled\libs\debugpy\__main__.py", line 39, in
cli.main()
File "c:\Users\.vscode\extensions\ms-python.debugpy-2024.10.0-win32-x64\bundled\libs\debugpy/..\debugpy\server\cli.py", line 430, in main
run()
File "c:\Users\.vscode\extensions\ms-python.debugpy-2024.10.0-win32-x64\bundled\libs\debugpy/..\debugpy\server\cli.py", line 284, in run_file
runpy.run_path(target, run_name="__main__")
File "c:\Users\.vscode\extensions\ms-python.debugpy-2024.10.0-win32-x64\bundled\libs\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 321, in run_path
return _run_module_code(code, init_globals, run_name,
File "c:\Users\.vscode\extensions\ms-python.debugpy-2024.10.0-win32-x64\bundled\libs\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 135, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "c:\Users\.vscode\extensions\ms-python.debugpy-2024.10.0-win32-x64\bundled\libs\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 124, in _run_code
exec(code, run_globals)
File "C:\Users\Desktop\CRAutomation\projectid.py", line 67, in
print(f"Project/CR IDs Consistent: {consistent}")
NameError: name 'consistent' is not defined

После удаления попробуйте, кроме:-
PS C:\Users\Desktop\repo\CR_Devops_Automate> c:; cd 'c:\Users\Desktop\repo\CR_Devops_Automate'; & 'c:\Python310\python.exe' 'c:\Users\.vscode\extensions\ms-python.debugpy-2024.10.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher' '56267' '--' 'C:\Users\703301396\Desktop\CRAutomation\projectid.py'
Title: test 123
Traceback (most recent call last):
File "c:\Python310\lib\runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "c:\Python310\lib\runpy.py", line 86, in _run_code
exec(code, run_globals)
File "c:\Users\703301396\.vscode\extensions\ms-python.debugpy-2024.10.0-win32-x64\bundled\libs\debugpy\__main__.py", line 39, in
cli.main()
File "c:\Users\.vscode\extensions\ms-python.debugpy-2024.10.0-win32-x64\bundled\libs\debugpy/..\debugpy\server\cli.py", line 430, in main
run()
File "c:\Users\.vscode\extensions\ms-python.debugpy-2024.10.0-win32-x64\bundled\libs\debugpy/..\debugpy\server\cli.py", line 284, in run_file
runpy.run_path(target, run_name="__main__")
File "c:\Users\.vscode\extensions\ms-python.debugpy-2024.10.0-win32-x64\bundled\libs\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 321, in run_path
return _run_module_code(code, init_globals, run_name,
File "c:\Users\.vscode\extensions\ms-python.debugpy-2024.10.0-win32-x64\bundled\libs\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 135, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "c:\Users\.vscode\extensions\ms-python.debugpy-2024.10.0-win32-x64\bundled\libs\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 124, in _run_code
exec(code, run_globals)
File "C:\Users\Desktop\CRAutomation\projectid.py", line 62, in
consistent = cr_or_project_value= check_project_cr_ids_consistency(work_item)
File "C:\Users\Desktop\CRAutomation\projectid.py", line 50, in check_project_cr_ids_consistency
recursive_check(work_item)
File "C:\Users\Desktop\CRAutomation\projectid.py", line 48, in recursive_check
recursive_check(child_work_item)
File "C:\Users\Desktop\CRAutomation\projectid.py", line 42, in recursive_check
for relation in item.relations:
TypeError: 'NoneType' object is not iterable


Подробнее здесь: https://stackoverflow.com/questions/790 ... onsistency
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Python»