Allure & Pytest - 자동화 테스트 결과 리포트 생성하기

Soyean·2023년 6월 20일
0

Allure-Report 

목록 보기
1/3

Allure는 테스트 실행 시, 아래처럼 html 형식으로 노출되어 한눈에 테스트 결과를 볼 수 있도록 합니다.
테스트 결과를 시각화하는 방법은 다양하지만 커스텀을 잘 하지 못하는 저 같은 사람에게 유용한 프레임워크 입니다. 😆

Allure는 Java / JavaScript / Python / Ruby / PHP / Kotlin and Android / .NET / Go 언어로 사용 가능합니다.

Extent Reports가 다양하게 사용되지만 python이 지원되지 않아 파이썬가 지원되는 allure로 테스트 프레임워크를 선택했습니다.

Allure Report command-line tool 설치

SCOOP 설치 방법 : https://scoop.sh/
BREW 설치 방법 : https://brew.sh/

FOR Windows > scoop install allure
FOR macOS and Linux > brew install allure

Allure Pytest Plugin 설치

pip install allure-pytest

Pycharm 인터프리터 설치

Pycharm 을 사용한다면, 인터프리터를 설치하여 allure를 설치할 수도 있습니다.

Preference → Project → Python 인터프리터 → 인터프리터 추가 → 이용 가능한 패키지

allure-pytest 검색하여 패키지 설치

Python 코드 작성하기 > Allure Feature

Allure는 기본적인 Pytest를 지원해주기 때문에 Pytest로 작성되었다면 별도 코드 수정 없이도 Allure 레포트가 노출됩니다.

  • pytest

  • @allure.step
    해당 주석을 추가하면, 주석이 추가된 메서드의 단계별 진행 상황을 확인할 수 있습니다.
    @step 주석이 달린 메서드는 테스트와 별도로 저장하고 필요할 때 가져올 수 있습니다. step 메소드는 임의의 깊은 중첩 구조를 가질 수 있습니다.
    Behaviors 탭 > method 클릭하여 Execution > Test body 영역에서 확인 가능합니다.

    step 메서드로는 전달된 매개변수를 포함하여 설명에 추가할 수 있습니다.
    아래 예시 코드에서는 step 메서드를 3번 호출했고 이를 통해 레포트에서 전달된 매개변수가 확인되었습니다.

    import allure
    
    @allure.step('Step with placeholders in the title, positional: "{0}", keyword: "{key}"')
    def step_with_title_placeholders(arg1, key=None):
        pass
    
    def test_steps_with_placeholders():
        step_with_title_placeholders(1, key='something')
        step_with_title_placeholders(2)
        step_with_title_placeholders(3, 'anything')

  • @allure.description
    해당 주석을 추가하여 메서드의 설명을 추가할 수 있습니다.

    @allure.description("""
    Multiline test description.
    That comes from the allure.description decorator.
    
    Nothing special about it.
    """)
    def test_description_from_decorator():
        assert 42 == int(6 * 7)


    아래처럼 HTML 형식으로도 추가할 수 있습니다.

    @allure.description_html("""
    <h1>Test with some complicated html description</h1>
    <table style="width:100%">
      <tr>
        <th>Firstname</th>
        <th>Lastname</th>
        <th>Age</th>
      </tr>
      <tr align="center">
        <td>William</td>
        <td>Smith</td>
        <td>50</td>
      </tr>
      <tr align="center">
        <td>Vasya</td>
        <td>Jackson</td>
        <td>94</td>
      </tr>
    </table>
    """)
    def test_html_description():
        assert True

  • allure.attach()
    테스트 결과 레포트에 텍스트나 이미지 등을 첨부할 수 있습니다.
    https://docs.pytest.org/en/stable/reference/reference.html#pytest.hookspec.pytest_runtest_makereport
    https://docs.pytest.org/en/stable/example/simple.html#post-process-test-reports-failures

Allure 결과 & 레포트 생성하기

1. Python 실행 시, Allure 결과 생성하기

--alluredir 옵션을 추가해주면 테스트 실행 시, Allure 리스너가 결과 수집 
$ py.test --alluredir=<Allure 결과 디렉토리명>  test.py

2. 테스트 완료 후, Allure 결과에서 레포트 생성하기

- 방법 1 > 레포트 생성 후 오픈

Allure 결과를 레포트로 생성 > allure-report 디렉토리로 레포트 생성
$ allure generate <Allure 결과 디렉토리명> 
-o 옵션으로 레포트 디렉토리명 지정 가능 
$ allure generate <Allure 결과 디렉토리명> -o <레포트 디렉토리명>
브라우저로 레포트가 열림 > -o 옵션으로 레포트 리덱토리명 별도 지정하지 않은 경우 allure-report 입력 
$ allure open <레포트 디렉토리명>

- 방법 2 > 레포트 생성과 동시에 오픈

아래 명령어 실행 시, 임시 폴더에 리포트 실행되고 즉시 브라우저로 열림 
$ allure serve <allure_result_folder>

3. Allure 레포트 데이터 삭제

allure-results 폴더의 레포트 데이터 삭제 > -o 옵션 사용하여 폴더 지정 가능 
allure report clean

참고 )
https://github.com/allure-framework/allure-python/tree/master/allure-pytest
https://docs.qameta.io/allure/#_pytest
https://github.com/allure-framework

profile
주니어 QA 🐥

0개의 댓글

관련 채용 정보