Skip to main content

pytest plugin to integrate tests with JIRA XRAY

Project description

PyPi Build status Code coverage

pytest-jira-xray is a plugin for pytest that uploads test results to JIRA XRAY.


Installing from pypi repository:

pip install -U pytest-jira-xray

Installing from local source:

pip install <path>

Installing from local source in development mode:

pip install -e <path>


Mark a test with JIRA XRAY test ID or list of IDs

# -- FILE:

import pytest

def test_foo():
    assert True

@pytest.mark.xray(['JIRA-2', 'JIRA-3'])
def test_bar():
    assert True

Jira Xray configuration can be provided via Environment Variables:

  • Jira base URL:

$ export XRAY_API_BASE_URL=<Jira base URL>
  • Basic authentication with username and password (default)

$ export XRAY_API_USER=<jria username>
$ export XRAY_API_PASSWORD=<user password>
  • Personal Access Token authentication (--api-key-auth option)

$ export XRAY_API_KEY=<api key>
  • SSL Client Certificate

To disable SSL certificate verification, at the client side (no case-sensitive), default is True:

$ export XRAY_API_VERIFY_SSL=False

Or you can provide path to certificate file

$ export XRAY_API_VERIFY_SSL=</path/to/PEM file>
  • Authentication with client ID and client secret (--client-secret-auth option):

$ export XRAY_CLIENT_ID=<client id>
$ export XRAY_CLIENT_SECRET=<client secret>
  • Test Execution parameters:

$ export XRAY_EXECUTION_REVISION=`git rev-parse HEAD`

$ export XRAY_EXECUTION_SUMMARY="Smoke tests" # New execution only
$ export XRAY_EXECUTION_DESC="This is an automated test execution of the smoke tests" # New execution only

Upload results

  • Upload results to new test execution:

$ pytest --jira-xray
  • Upload results to existing test execution:

$ pytest --jira-xray --execution TestExecutionId
  • Upload results to existing test plan (new test execution will be created):

$ pytest --jira-xray --testplan TestPlanId
  • Store results in a file instead of exporting directly to a XRAY server

$ pytest --jira-xray --xraypath=xray.json
  • Use with Jira cloud:

The Xray REST API may use two different endpoints: Server+DC or Cloud. There is a difference between formats of test results (test status can be PASS or PASSED), so if you want to use this plugin with Xray Cloud endpoint you should run pytest with additional argument --cloud. This will generate test results with the format accepted by the Cloud service.

$ pytest --jira-xray --cloud

Jira authentication

It is default authentication.

$ pytest --jira-xray --client-secret-auth
$ pytest --jira-xray --api-key-auth

Multiple ids support

Tests can be marked to handle multiple Jira tests by adding a list, rather than a string. Example:

# -- FILE:

import pytest

def test_my_process():
    assert True

If the test fails, both JIRA-1 and JIRA-2 tests will be marked as fail. The failure comment will contain the same message for both tests.

This situation can be useful for validation tests or tests that probe multiple functionalities in a single run, to reduce execution time.

Duplicated ids support

By default, the jira-xray plugin does not allow to have multiple tests marked with the same identifier, like in this case:

# -- FILE:

import pytest

def test_my_process_1():
    assert True

def test_my_process_2():
    assert True

However, depending how the user story and the associated test are formulated, this scenario may be useful. The option --allow-duplicate-ids will perform the tests even when duplicate ids are present. The JIRA-1 test result will be created according to the following rules:

  • The comment will be the comment from each of the test, separated by a horizontal divider.

  • The status will be the intuitive combination of the individual results: if test_my_process_1 is a PASS but test_my_process_2 is a FAIL, JIRA-1 will be marked as FAIL.

Attach test evidences

The following example adds the test evidences to the Xray report using a pytest_runtest_makereport hook.

# -- FILE:

import pytest
from pytest_xray import evidence

def pytest_runtest_makereport(item, call):
    outcome = yield
    report = outcome.get_result()
    evidences = getattr(report, "evidences", [])
    if report.when == "call":
        xfail = hasattr(report, "wasxfail")
        if (report.skipped and xfail) or (report.failed and not xfail):
            data = open("screenshot.jpeg", "rb").read()
            evidences.append(evidence.jpeg(data=data, filename="screenshot.jpeg"))
        report.evidences = evidences


There is possibility to modify a XRAY report before it is send to a server by pytest_xray_results hook.

def pytest_xray_results(results, session):
    results['info']['user'] = 'pytest'

IntelliJ integration

When you want to synchronize your test results via. Pytest integration in IntelliJ, you need to configure the following:

  1. Use the pytest test configuration template and add --jira-xray -o log_cli=true to Additional Arguments
  1. Disable –no-summary in Settings


This section holds information about common issues.

The Test XXX is in a non-executable status

  • Problem: The test is not executable by the user.

  • Solution: Make sure, that your test is not deactivated, approved and ready to use in Jira.

Error message from server: fixVersions: fixVersions

  • Problem: The version is malformed or doesn’t exist.

  • Solution: Make sure the version exists and the name matches the existing version and that only one version is used.


Project details

Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

pytest_jira_xray-0.8.11-py3-none-any.whl (19.8 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