Я пытаюсь автоматизировать API с помощью pytest. Я хочу включить status_code в качестве одного из столбцов в html отчета, созданного с использованием pytest-html. Я собрал status_code в одну переменную в тестовой функции. Но как передать его, чтобы подключить в контесте.
Файл моего модульного теста имеет следующий код.
class Test1(unittest.TestCase):
def test1_cust_list_page(self):
cust_list_resp = requests.post(BASE_URL+customer_list_ep,json=cust_page_payload,headers=headers,params=cust_list_params)
print(cust_list_resp.status_code)
status_code = cust_list_resp.status_code
assert cust_list_resp.status_code==200
Мой файл контеста имеет следующий код:
from datetime import datetime
from py.xml import html
import pytest
@pytest.mark.optionalhook
def pytest_html_results_table_header(cells):
cells.insert(2, html.th('Status_code'))
cells.insert(1, html.th('Time', class_='sortable time', col='time'))
cells.pop()
@pytest.mark.optionalhook
def pytest_html_results_table_row(report, cells):
cells.insert(2, html.td(report.status_code))
cells.insert(1, html.td(datetime.utcnow(), class_='col-time'))
cells.pop()
@pytest.mark.hookwrapper
def pytest_runtest_makereport(item, call):
outcome = yield
report = outcome.get_result()
report.status_code = str(item.function.)
Какой код должен быть в последней строке, если я хочу вызвать значение status_code из юнит-теста test1_cust_list_page.
Я ссылаюсь на приведенный ниже стек, но во втором варианте не ясно, какую функцию вызывать.
Как добавить дополнительную переменную в HTML-отчет Pytest