Python Unit Test, Pytest : Part 1

preview_player
Показать описание
This video shows basic use of python unit test and pytest modules. Also shows some command line arguments for pytest and how to generate a html report.
Рекомендации по теме
Комментарии
Автор

you have covered such good material through the entire playlist. Thank you!!

batasheemum
Автор

Thanks for session. very nice and useful

mallikarjunyaramala
Автор

I am trying to do API automation using pytest. I want to include status_code as one of the columns in the report html generated using pytest-html. I collected the status_code in one variable in test function. But how to pass it to hook in conftest.

My unit test file has below 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)

status_code = cust_list_resp.status_code
assert
My conftest file has the below code:

from datetime import datetime
from py.xml import html
import pytest

@pytest.mark.optionalhook
def
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.)
What the code should be in the last line, if I want to invoke value of status_code from test1_cust_list_page unit test.

Dinesh-rzsj
Автор

Can I add Browser (Firefox, Chrome) to Environment table?

vanvo