pytest-jira-xray is a plugin for pytest that uploads test results to JIRA XRAY.
pip install pytest-jira-xray
or
python setup.py install
Mark a test with JIRA XRAY test ID or list of IDs
# -- FILE: test_example.py
import pytest
@pytest.mark.xray('JIRA-1')
def test_foo():
assert True
@pytest.mark.xray(['JIRA-2', 'JIRA-3'])
def test_bar():
assert True
In the test methods corresponding test IDs are accessable via environment variable XRAY_TEST_IDS. If multiple test IDs were provided they will be separated by a space:
JIRA_TEST_IDS=JIRA-1 JIRA_TEST_IDS=JIRA-1 JIRA-2 JIRA-3
- Jira base URL:
$ export XRAY_API_BASE_URL=<Jira base URL>
- Basic authentication (default):
$ export XRAY_API_USER=<jria username>
$ export XRAY_API_PASSWORD=<user password>
- API KEY (--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>
- Token authentication (--token-auth option)
$ export XRAY_API_TOKEN=<user token>
- Test Execution parameters:
$ export XRAY_EXECUTION_TEST_ENVIRONMENTS="Env1 Env2 Env3"
$ export XRAY_EXECUTION_FIX_VERSION="1.0"
$ 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 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:
$ pytest --jira-xray --cloud
Default Jira authentication is basic authentication, but you can select different authentication.
- Jira client secret authentication:
$ pytest --jira-xray --client-secret-auth
- Jira API KEY authentication:
$ pytest --jira-xray --api-key-auth
- Jira token authentication:
$ pytest --jira-xray --token-auth
Tests can be marked to handle multiple Jira tests by adding a list, rather than a string. Example:
# -- FILE: test_example.py
import pytest
@pytest.mark.xray([
'JIRA-1',
'JIRA-2'
])
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.
By default, the jira-xray plugin does not allow to have multiple tests marked with the same identifier, like in this case:
# -- FILE: test_example.py
import pytest
@pytest.mark.xray('JIRA-1')
def test_my_process_1():
assert True
@pytest.mark.xray('JIRA-1')
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 aPASS
buttest_my_process_2
is aFAIL
,JIRA-1
will be marked asFAIL
.
When you want to synchronize your test results via. Pytest integration in IntelliJ, you need to configure the following:
- Use the pytest test configuration template and add --jira-xray -o log_cli=true to Additional Arguments
- Disable --no-summary in Settings
This section holds information about common issues.
- 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.
- 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.
- XRay import execution endpoint: https://docs.getxray.app/display/XRAY/Import+Execution+Results