TestRail : pytest-testrail로 테스트 결과 전송하기

Soyean·2023년 10월 10일

Python

목록 보기
1/2

TestRail API 사용하여 Python과 연동하기 에서 TestRail API를 직접 Python과 연동했습니다.
테스트 결과만을 추가하려면 pytest-testrail을 사용하여 조금 더 쉽게 TestRail에 전송할 수 있습니다.

1. pytest-testrail 설치

pip install pytest-testrail

2. Config 파일 추가

TestRail을 위한 기본 설정 파일을 생성합니다. (파일명 : testrail.cfg)
TESTRUN에 필요한 필드값은 TestRail API 사용하여 Python과 연동하기에서 확인할 수 있습니다.

    [API]
    url = https://yoururl.testrail.net/
    email = user@email.com
    password = <api_key>

    [TESTRUN]
    assignedto_id = 1
    project_id = 2
    suite_id = 3
    plan_id = 4
    description = 'This is an example description'

    [TESTCASE]
    custom_comment = 'This is a custom comment'

3. Pytest test 설정

cfg 파일에서 설정한 run에 대한 테스트 결과를 추가할 수 있습니다.

  • 테스트 케이스에 테스트 메소드 실행 결과 추가
    Case 1 : testrail 임포트 > Test 메소드에 @testrail('Case_id') 데코레이터 추가

     from pytest_testrail.plugin import testrail
    
      @testrail('C1234', 'C5678')
      def test_foo():
          # test code goes here

    Case 2 : pytestrail 임포트 > Test 메소드에 @pytestrail.case('Case_id') 데코레이터 추가

     from pytest_testrail.plugin import pytestrail
    
      @pytestrail.case('C1234', 'C5678')
      def test_bar():
          # test code goes here
  • 테스트 케이스 결과에 대해 defects 추가

     from pytest_testrail.plugin import pytestrail
    
      @pytestrail.defect('PF-524', 'BR-543')
      def test_bar():
          # test code goes here

4. Pytest 실행

cfg 파일명이 testrail인 경우 (testrail.cfg) , --testrail만 추가 후 실행하면 run이 생성되고 업데이트됩니다.

py.test --testrail

cfg 파일명이 testrail이 아닌 경우(<settings file>.cfg) , --testrail과 함께 --tr-config=<settings file>.cfg 를 추가해줘야 합니다.

py.test --testrail --tr-config=<settings file>.cfg

cfg 파일을 생성하지 않은 경우, --testrail과 함께 All available options 을 추가해줘야 합니다.

py.test --testrail --tr-url="https://yoururl.testrail.net/" --tr-email ... 

All available options 목록

--testrail            Create and update testruns with TestRail
--tr-config=TR_CONFIG
                      Path to the config file containing information about
                      the TestRail server (defaults to testrail.cfg)
--tr-url=TR_URL       TestRail address you use to access TestRail with your
                      web browser (config file: url in API section)
--tr-email=TR_EMAIL   Email for the account on the TestRail server (config
                      file: email in API section)
--tr-password=TR_PASSWORD
                      Password for the account on the TestRail server
                      (config file: password in API section)
--tr-testrun-assignedto-id=TR_TESTRUN_ASSIGNEDTO_ID
                      ID of the user assigned to the test run (config file:
                      assignedto_id in TESTRUN section)
--tr-testrun-project-id=TR_TESTRUN_PROJECT_ID
                      ID of the project the test run is in (config file:
                      project_id in TESTRUN section)
--tr-testrun-suite-id=TR_TESTRUN_SUITE_ID
                      ID of the test suite containing the test cases (config
                      file: suite_id in TESTRUN section)
--tr-testrun-suite-include-all
                      Include all test cases in specified test suite when
                      creating test run (config file: include_all in TESTRUN
                      section)
--tr-testrun-name=TR_TESTRUN_NAME
                      Name given to testrun, that appears in TestRail
                      (config file: name in TESTRUN section)
--tr-run-id=TR_RUN_ID
                      Identifier of testrun, that appears in TestRail. If
                      provided, option "--tr-testrun-name" will be ignored
--tr-plan-id=TR_PLAN_ID
                      Identifier of testplan, that appears in TestRail. If
                      provided, option "--tr-testrun-name" will be ignored
--tr-version=TR_VERSION
                      Indicate a version in Test Case result.
--tr-no-ssl-cert-check
                      Do not check for valid SSL certificate on TestRail
                      host
--tr-close-on-complete
                      Close a test plan or test run on completion.
--tr-dont-publish-blocked
                      Do not publish results of "blocked" testcases in
                      TestRail
--tr-skip-missing     Skip test cases that are not present in testrun

참고 :
https://github.com/allankp/pytest-testrail/

profile
주니어 QA 🐥

0개의 댓글