pyte-Te를 사용하여 테스트 함수의 docstring을 보고서에 출력

3733 단어 pytestPython
테스트 함수에 대한 상세한 정보로 docstring을pyte-in 보고서에 출력하는 방법을 총괄하였다.

1. conftest.py 편집


테스트 디렉터리 바로 아래에 있는 conftest입니다.py(그렇지 않으면 생성)에 다음 설정을 추가합니다.
표 머리글의 3열에 제목, 표 주체의 3열에 테스트 함수의docsting 정보를 삽입합니다.
conftest.py
import pytest
from py.xml import html


def pytest_html_results_table_header(cells):
    cells.insert(2, html.th('Description'))

def pytest_html_results_table_row(report, cells):
    cells.insert(2, html.td(report.description))

@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_makereport(item, call):
    outcome = yield
    report = outcome.get_result()
    report.description = str(item.function.__doc__)

2. 테스트 코드에 docstring 쓰기

def test_one(self):
    """
    これはテスト1です
    """
    assert True

def test_two(self):
    """
    これはテスト2です
    """
    assert False

3. 테스트 구현

$ pytest --html=report.html

4. 결과


표의 세 번째 열에는 각 테스트 함수의 docstring이 표시되어 있습니다.

참고 자료

  • https://github.com/pytest-dev/pytest-html
  • 좋은 웹페이지 즐겨찾기