Skip to main content

pytest plugin for creating TestRail runs and adding results

Project description

PyPI version Downloads MIT license pytest

This is a pytest plugin for creating/editing testplans or testruns based on pytest markers. The results of the collected tests will be updated against the testplan/testrun in TestRail.


pip install pytest-testrail-e2e


Config for Pytest tests

Add a marker to the tests that will be picked up to be added to the run.

from pytest_testrail.plugin import testrail

@testrail('C1234', 'C5678')
def test_foo():
    # test code goes here

# OR

from pytest_testrail.plugin import pytestrail"C1234", "C5678")
def test_bar():
    # test code goes here

Or if you want to add defects to testcase result:

from pytest_testrail.plugin import pytestrail

@pytestrail.defect("PF-524", "BR-543")
def test_bar():
    # test code goes here

Skip a testcase [You need create ‘Skipped’ status in TestRail’]:

from pytest_testrail.plugin import pytestrail"C1234")
@pytest.mark.skip("Mark as skipped description")
# or @pytest.mark.skip(reason="Mark as skipped description")
def test_bar():
    # test code goes here

Block a testcase:

import pytest
from pytest_testrail.plugin import pytestrail"C1234")
@pytestrail.block("Mark as blocked description")
# @pytestrail.block(reason="Mark as blocked description")
def test_bar():
    # test code goes here

# OR"C1234")
@pytest.mark.skip(reason="Mark as blocked description", block=True)
def test_bar():
    # test code goes here

How to set known defect ID for specific assertion: set pytest-defect=<defect_id> in assertion error message.

from pytest_testrail.plugin import pytestrail"C1234")
def test_bar():
    # Assertion 1: defect NCT-836
    assert 1==0, "pytest-defect=NCT-836"
    # Assertion 2: defect NCT-1024
    assert False, "Error message contains regex: pytest-defect=NCT-1024 allows to insert defect 'NCT-1024'"

Config for TestRail

  • Settings file template config:

url =
email =
password = <api_key>

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

custom_comment = 'This is a custom comment'


  • Set command line options (see below)


Basically, the following command will create a testrun in TestRail, add all marked tests to run. Once the all tests are finished they will be updated in TestRail:

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

All available options




Create and update testruns with TestRail


Path to the config file containing information about the TestRail server (defaults to testrail.cfg)


TestRail address you use to access TestRail with your web browser (config file: url in API section)


Email for the account on the TestRail server (config file: email in API section)


Password for the account on the TestRail server (config file: password in API section)

–tr-testrun-as signedto-id

ID of the user assigned to the test run (config file:assignedto_id in TESTRUN section)

–tr-testrun-pr oject-id

ID of the project the test run is in (config file: project_id in TESTRUN section)

–tr-testrun-su ite-id

ID of the test suite containing the test cases (config file: suite_id in TESTRUN section)

–tr-testrun-su ite-include-all

Include all test cases in specified test suite when creating test run (config file: include_all in TESTRUN section)

–tr-testrun-na me

Name given to testrun, that appears in TestRail (config file: name in TESTRUN section)

–tr-testrun-de scription

Description given to testrun, that appears in TestRail (config file: description in TESTRUN section)


Identifier of testrun, that appears in TestRail. If provided, option “–tr-testrun-name” will be ignored


Identifier of testplan, that appears in TestRail. If provided, option “–tr-testrun-name” will be ignored


Indicate a version in Test Case result.

–tr-no-ssl-cer t-check

Do not check for valid SSL certificate on TestRail host

–tr-close-on-c omplete

Close a test plan or test run on completion.

–tr-dont-publi sh-blocked

Do not publish results of “blocked” testcases in TestRail

–tr-skip-missi ng

Skip test cases that are not present in testrun

–tr-milestone- id

Identifier of milestone to be assigned to run

–tc-custom-com ment

Custom comment, to be appended to default comment for test case (config file: custom_comment in TESTCASE section)

–tr-report-sin gle-test

Report result immediately for each test case when it finished

TestRail Settings

To increase security, the TestRail team suggests using an API key instead of a password. You can see how to generate an API key here.

If you maintain your own TestRail instance on your own server, it is recommended to enable HTTPS for your TestRail installation.

For TestRail hosted accounts maintained by Gurock, all accounts will automatically use HTTPS.

You can read the whole TestRail documentation here.


NGUYEN Viet - github


This project is licensed under the MIT license.


Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest-testrail-e2e-2.2.3.tar.gz (14.5 kB view hashes)

Uploaded Source

Built Distribution

pytest_testrail_e2e-2.2.3-py3-none-any.whl (14.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page