Package: pytest-jira-xray
pytest-jira-xray is a plugin for pytest that uploads test results to JIRA XRAY.InstallationInstalling from pypi repository:pip install -U pytest-jira-xrayInstalling from local source:pip install <path>Installing from local source in development mode:pip install -e <path>UsageMark a test with JIRA XRAY test ID or list of IDs# -- FILE: test_example.pyimportpytest@pytest.mark.xray('JIRA-1')deftest_foo():assertTrue@pytest.mark.xray(['JIRA-2','JIRA-3'])deftest_bar():assertTrueJira Xray configuration can be provided via Environment Variables:Jira base URL:$exportXRAY_API_BASE_URL=<JirabaseURL>Basic authentication with username and password (default)$exportXRAY_API_USER=<jriausername>$exportXRAY_API_PASSWORD=<userpassword>Personal Access Token authentication (–api-key-authoption)$exportXRAY_API_KEY=<apikey>SSL Client CertificateTo disable SSL certificate verification, at the client side (no case-sensitive), default is True:$exportXRAY_API_VERIFY_SSL=FalseOr you can provide path to certificate file$exportXRAY_API_VERIFY_SSL=</path/to/PEMfile>Authentication with client ID and client secret (--client-secret-authoption):$exportXRAY_CLIENT_ID=<clientid>$exportXRAY_CLIENT_SECRET=<clientsecret>Test Execution parameters:$exportXRAY_EXECUTION_TEST_ENVIRONMENTS="Env1 Env2 Env3"$exportXRAY_EXECUTION_FIX_VERSION="1.0"$exportXRAY_EXECUTION_REVISION=`gitrev-parseHEAD`$exportXRAY_EXECUTION_SUMMARY="Smoke tests"# New execution only$exportXRAY_EXECUTION_DESC="This is an automated test execution of the smoke tests"# New execution onlyUpload resultsUpload results to new test execution:$pytest--jira-xrayUpload results to existing test execution:$pytest--jira-xray--executionTestExecutionIdUpload results to existing test plan (new test execution will be created):$pytest--jira-xray--testplanTestPlanIdStore results in a file instead of exporting directly to a XRAY server$pytest--jira-xray--xraypath=xray.jsonUse with Jira cloud:$pytest--jira-xray--cloudJira authenticationJirabasic authentication:It is default authentication.Jira authentication withClient ID and a Client Secret:$pytest--jira-xray--client-secret-authJiraPersonal access tokens(API KEY) authentication:$pytest--jira-xray--api-key-authMultiple ids supportTests can be marked to handle multiple Jira tests by adding a list, rather than a string. Example:# -- FILE: test_example.pyimportpytest@pytest.mark.xray(['JIRA-1','JIRA-2'])deftest_my_process():assertTrueIf 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 supportBy default, the jira-xray plugin does not allow to have multiple tests marked with
the same identifier, like in this case:# -- FILE: test_example.pyimportpytest@pytest.mark.xray('JIRA-1')deftest_my_process_1():assertTrue@pytest.mark.xray('JIRA-1')deftest_my_process_2():assertTrueHowever, depending how the user story and the associated test are formulated,
this scenario may be useful. The option--allow-duplicate-idswill 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: iftest_my_process_1is aPASSbuttest_my_process_2is aFAIL,JIRA-1will be marked asFAIL.Attach test evidencesThe following example adds the test evidences to the Xray report
using apytest_runtest_makereporthook.# -- FILE: conftest.pyimportpytestfrompytest_xrayimportevidence@pytest.hookimpl(hookwrapper=True)defpytest_runtest_makereport(item,call):outcome=yieldreport=outcome.get_result()evidences=getattr(report,"evidences",[])ifreport.when=="call":xfail=hasattr(report,"wasxfail")if(report.skippedandxfail)or(report.failedandnotxfail):data=open("screenshot.jpeg","rb").read()evidences.append(evidence.jpeg(data=data,filename="screenshot.jpeg"))report.evidences=evidencesHooksThere is possibility to modify a XRAY report before it is send to a server bypytest_xray_resultshook.defpytest_xray_results(results,session):results['info']['user']='pytest'IntelliJ integrationWhen you want to synchronize your test results via. Pytest integration in IntelliJ, you need to configure the following:Use thepytesttest configuration template and add--jira-xray-olog_cli=truetoAdditional ArgumentsDisable–no-summaryinSettingsTroubleshootingThis section holds information about common issues.The Test XXX is in a non-executable statusProblem: 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: fixVersionsProblem: 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.ReferencesXRay import execution endpoint:https://docs.getxray.app/display/XRAY/Import+Execution+Results