2017-04-05 2 views
2

셀렌 테스트를 위해 pytest HTML 보고서 플러그인을 사용하고 있습니다. test.py --html==report.htmlin 명령 줄을 전달하는 것만으로 효과적이며 훌륭한 보고서를 생성합니다.pytest html 보고서에 추가 변수를 추가하는 방법

각 테스트 케이스 디스플레이에 추가 문자열/변수를 구현해야합니다. 합격했는지 실패했는지는 중요하지 않습니다. 티켓 번호 만 표시하면됩니다. 각 테스트 시나리오에서 반환 할 수있는 티켓 ID입니다.

테스트 이름에 티켓 번호를 추가 할 수는 있지만 못 생길 것입니다.

가장 좋은 방법은 무엇입니까?

감사합니다.

답변

3

각 테스트의 '세부 정보 표시'섹션에 html 콘텐츠를 추가하거나 결과 표 사용자 정의 (예 : 티켓 열 추가)를 통해 각 테스트에 맞춤 html을 삽입 할 수 있습니다. 콘텐츠에 당신이 <p>some html</p>을 대체 할 수있는 경우

첫 번째 가능성

는 간단합니다, 당신은 당신의 conftest.py

@pytest.mark.hookwrapper 
def pytest_runtest_makereport(item, call): 
    pytest_html = item.config.pluginmanager.getplugin('html') 
    outcome = yield 
    report = outcome.get_result() 
    extra = getattr(report, 'extra', []) 
    if report.when == 'call': 
     extra.append(pytest_html.extras.html('<p>some html</p>')) 
     report.extra = extra 

에 다음을 추가 할 수 있습니다.

두 번째 솔루션은 다음과 같습니다

@pytest.mark.optionalhook 
def pytest_html_results_table_header(cells): 
    cells.insert(1, html.th('Ticket')) 


@pytest.mark.optionalhook 
def pytest_html_results_table_row(report, cells): 
    cells.insert(1, html.td(report.ticket)) 


@pytest.mark.hookwrapper 
def pytest_runtest_makereport(item, call): 
    outcome = yield 
    report = outcome.get_result() 
    report.ticket = some_function_that_gets_your_ticket_number() 

는 항상 항목 개체와 현재 테스트에 액세스 할 수 있는지 기억이 당신이 필요로하는 정보를 검색하는 도움이 될 수 있습니다.