Skip to main content

Behave to TestRail Reporter

CircleCI Codacy Badge Codacy Badge pullreminders

This integration is used to add test results to TestRail automatically when Behave tests are executed.

Example of the generated report:

3 testrail test cases passed, 0 failed, 19 skipped, 2 untested
Took 0m6.349s

Install

Can install it using pipenv

$ pipenv install behave-testrail-reporter

or using pip

$ pip install behave-testrail-reporter

Setup

Add TestrailReporter to behave reporters in your /features/environment.py by adding this code in before_all()

from behave_testrail_reporter import TestrailReporter

def before_all(context):
    # ... all your other awesome code in here
    current_branch = os.environ.get('CIRCLE_BRANCH') # Change this to get the current build branch of your CI system
    testrail_reporter = TestrailReporter(current_branch)
    context.config.reporters.append(testrail_reporter)

Create a testrail.yml config file in the root of your project

Example structure:

base_url: https://your-domain.testrail.io
projects:
  - name: 'Advanced tests on branch {branch}'
    id: 123
    suite_id: 456
    # note: this will allow any branch to push test case results to Testrail.
    allowed_branch_pattern: '.*'
  - name: 'Smoke tests on branch {branch}'
    id: 1234
    suite_id: 789
    # note: this will allow any branch to push test case results to Testrail.
    allowed_branch_pattern: '.*'

Allow only master branch and release1.111.1 to push test results to Testrail:

base_url: https://your-domain.testrail.io
projects:
  - name: 'Full E2E tests on branch {branch}'
    id: 123
    suite_id: 456
    allowed_branch_pattern: '^(master|release\/\d+([\.\d]+)?)$'
yaml key Description
name Project name
id Testrail project id
suite_id Testrail Suite id
allowed_branch_pattern Regular expression to restrict when a test run is executed

name - You can use some project variables to create dynamic test run names

Variable Example Result
{project_id} 'Test run {project_id}' Test run 123
{suite_id} 'Test run {suite_id}' Test run 456
{branch} 'Test run {branch}' Test run master

Environment variables required

Variable name Description
TESTRAIL_KEY TestRail user password
TESTRAIL_USER TestRail user email address

How to use

To get test cases marked as success or fail on TestRail we have to add tags with TestRail test case ID on each scenario.

Test case tag structure:

prefix + test case id

@testrail- + C1104

See example below:

Feature: Log in and out

    Background:
        Given I am logged out from Hub
        And I navigate to the home page

    @testrail-C1104
    @testrail-C45933
    Scenario: Admin can login
        When I enter the username admin
        And I enter the password admin
        And I click the Login button
        Then I see the admin's landing page

Note: some scenarios can cover multiple TestRail cases, for that you just need to add multiple tags.

How to contribute

Install dependencies for development

pipenv install --dev

How to run tests

Activate your virtual environment and then just run tox.

tox

How to distribute

If you need to publish a new version of this package you can use this command:

python setup.py sdist bdist_wheel
twine upload dist/*

License

Licensed under MIT license. View license.

Release files for behave-testrail-reporter 0.5.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for behave-testrail-reporter 0.5.1
File Size Uploaded
behave-testrail-reporter-0.5.1.tar.gz 13.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for behave-testrail-reporter 0.5.1
File Interpreter ABI Platform
behave_testrail_reporter-0.5.1-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 22.1 kB

Release files / behave-testrail-reporter-0.5.1.tar.gz

Download URL behave-testrail-reporter-0.5.1.tar.gz
Size 13.0 kB
Tags Source
SHA-256 checksum
How to use checksums
e424b01324769a6547fb4c8c6a4d3c7a973036243a287175ccfb820dba18693c
BLAKE2b-256 checksum
How to use checksums
e41d5ecff596161601dda81a7d7057c48b9733e846eb48fce598e22e7bbe6398
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.6.11

Release files / behave_testrail_reporter-0.5.1-py2.py3-none-any.whl

Download URL behave_testrail_reporter-0.5.1-py2.py3-none-any.whl
Size 9.0 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
f0fad50c6c3a27ae6e8919736b474c8d520dd6bc3c710d3764b93570b4b43a54
BLAKE2b-256 checksum
How to use checksums
29ac781b519463577eddbedec43c738193dde5fae4838dcfa2981a61980b562d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.6.11

Release history Release notifications | RSS feed

This release

0.5.1 This release

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page