### Install pytest-jira-xray from PyPI Source: https://github.com/fundakol/pytest-jira-xray/blob/master/README.rst Install the plugin using pip from the Python Package Index. ```bash pip install -U pytest-jira-xray ``` -------------------------------- ### Install pytest-jira-xray from Local Source Source: https://github.com/fundakol/pytest-jira-xray/blob/master/README.rst Install the plugin from a local source directory using pip. ```bash pip install ``` -------------------------------- ### Install pytest-jira-xray in Development Mode Source: https://github.com/fundakol/pytest-jira-xray/blob/master/README.rst Install the plugin from a local source directory in editable mode for development. ```bash pip install -e ``` -------------------------------- ### Attach Test Evidences with Pytest-Jira-Xray Hook Source: https://github.com/fundakol/pytest-jira-xray/blob/master/README.rst Implement the pytest_runtest_makereport hook in conftest.py to attach test evidences, such as screenshots, to Xray reports. This example attaches a JPEG evidence for failed tests. ```python # -- FILE: conftest.py import pytest from pytest_xray import evidence @pytest.hookimpl(hookwrapper=True) 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 ``` -------------------------------- ### Modify Xray Report with pytest_xray_results Hook Source: https://github.com/fundakol/pytest-jira-xray/blob/master/README.rst Use the pytest_xray_results hook to modify the Xray report data before it is sent to the server. This example adds user information to the report. ```python def pytest_xray_results(results, session): results['info']['user'] = 'pytest' ``` -------------------------------- ### Configure Basic Authentication Source: https://github.com/fundakol/pytest-jira-xray/blob/master/README.rst Set JIRA username and password using environment variables for basic authentication. ```bash $ export XRAY_API_USER= $ export XRAY_API_PASSWORD= ``` -------------------------------- ### Configure Personal Access Token Authentication Source: https://github.com/fundakol/pytest-jira-xray/blob/master/README.rst Set the API key using an environment variable for authentication with Personal Access Tokens. ```bash $ export XRAY_API_KEY= ``` -------------------------------- ### Configure pytest-jira-xray using environment variables Source: https://context7.com/fundakol/pytest-jira-xray/llms.txt Set environment variables to configure the server URL, authentication method, and test execution metadata. XRAY_API_BASE_URL is always required. Other variables depend on the chosen authentication mode. ```bash # ── Required ────────────────────────────────────────────────────────────────── export XRAY_API_BASE_URL="https://jira.example.com" # ── Basic authentication (default, no extra CLI flag needed) ────────────────── export XRAY_API_USER="ci-bot" export XRAY_API_PASSWORD="s3cr3t" # ── Personal Access Token / API Key (use with --api-key-auth) ──────────────── export XRAY_API_KEY="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." # ── OAuth2 Client Secret (use with --client-secret-auth) ──────────────────── export XRAY_CLIENT_ID="abc123clientid" export XRAY_CLIENT_SECRET="supersecretvalue" # ── SSL verification (default True; False to disable; path for custom CA) ───── export XRAY_API_VERIFY_SSL="False" export XRAY_API_VERIFY_SSL="/etc/ssl/certs/company-ca.pem" # ── Test Execution metadata ─────────────────────────────────────────────────── export XRAY_EXECUTION_SUMMARY="Nightly smoke tests" export XRAY_EXECUTION_DESC="Automated run triggered by CI pipeline" export XRAY_EXECUTION_REVISION="$(git rev-parse HEAD)" export XRAY_EXECUTION_FIX_VERSION="2.4.0" export XRAY_EXECUTION_TEST_ENVIRONMENTS="staging linux" # space-separated # ── Full invocation combining env + CLI ─────────────────────────────────────── pytest tests/ --jira-xray --testplan PROJ-300 --add-captures ``` -------------------------------- ### Configure Test Execution Parameters Source: https://github.com/fundakol/pytest-jira-xray/blob/master/README.rst Set environment variables for test environments, fix versions, revision, summary, and description for test executions. ```bash $ 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 ``` -------------------------------- ### Configure Client ID and Client Secret Authentication Source: https://github.com/fundakol/pytest-jira-xray/blob/master/README.rst Set JIRA client ID and client secret using environment variables for authentication. ```bash $ export XRAY_CLIENT_ID= $ export XRAY_CLIENT_SECRET= ``` -------------------------------- ### Jira Basic Authentication Source: https://github.com/fundakol/pytest-jira-xray/blob/master/README.rst The plugin uses JIRA basic authentication by default. No additional configuration is needed if this is your authentication method. ```bash # Default authentication method ``` -------------------------------- ### Configure SSL Certificate Verification Source: https://github.com/fundakol/pytest-jira-xray/blob/master/README.rst Control SSL certificate verification by setting XRAY_API_VERIFY_SSL to False or a path to a PEM file. ```bash $ export XRAY_API_VERIFY_SSL=False ``` ```bash $ export XRAY_API_VERIFY_SSL= ``` -------------------------------- ### Enable pytest-jira-xray plugin and control upload behavior via CLI Source: https://context7.com/fundakol/pytest-jira-xray/llms.txt Use the --jira-xray CLI option to activate the plugin. Combine it with other flags to specify the target execution, test plan, cloud mode, output file, or to include additional test information. ```bash # Upload to a new test execution (auto-created by XRAY) pytest --jira-xray # Upload to an existing Test Execution issue pytest --jira-xray --execution PROJ-500 # Upload to a Test Plan (a new execution is created inside it) pytest --jira-xray --testplan PROJ-300 # Use Jira Cloud endpoint (status values become PASSED/FAILED instead of PASS/FAIL) pytest --jira-xray --cloud # Save results to a JSON file instead of uploading pytest --jira-xray --xraypath=results/xray-report.json # Allow duplicate JIRA IDs across multiple tests (results are merged) pytest --jira-xray --allow-duplicate-ids # Include captured stdout, stderr, and log output in the comment field pytest --jira-xray --add-captures ``` -------------------------------- ### Build and Serialize XRAY Test Execution Data with TestExecution and TestCase Source: https://context7.com/fundakol/pytest-jira-xray/llms.txt Manually construct TestExecution objects by appending TestCase results. TestCase.merge() combines results for the same JIRA key, prioritizing the worst status and concatenating comments. The TestExecution object can then be serialized to the XRAY wire format using as_dict(). ```python from pytest_xray.helper import TestExecution, TestCase, Status, STATUS_STR_MAPPER_CLOUD # Build a TestExecution manually execution = TestExecution( test_execution_key='PROJ-500', # existing execution; omit to create new test_plan_key='PROJ-300', fix_version='2.4.0', summary='Regression suite', description='Triggered by merge to main', test_environments=['staging', 'linux'], revision='a1b2c3d4', ) # Add individual test results execution.append(TestCase( test_key='PROJ-101', status=Status.PASS, status_str_mapper=STATUS_STR_MAPPER_CLOUD, # use PASSED/FAILED for Cloud )) execution.append(TestCase( test_key='PROJ-102', status=Status.FAIL, comment='AssertionError at line 42', defects=['BUG-77'], )) # Merge duplicate-ID results tc_a = TestCase('PROJ-103', Status.PASS, comment='First run OK') tc_b = TestCase('PROJ-103', Status.FAIL, comment='Second run failed') tc_a.merge(tc_b) print(tc_a.status) # Status.FAIL (FAIL wins over PASS in the priority ladder) # Serialise to the wire format payload = execution.as_dict() ``` -------------------------------- ### Upload Results to Test Plan Source: https://github.com/fundakol/pytest-jira-xray/blob/master/README.rst Use the --testplan flag with the test plan ID to create a new test execution and upload results to it within a JIRA XRAY test plan. ```bash $ pytest --jira-xray --testplan TestPlanId ``` -------------------------------- ### Configure Jira Base URL Source: https://github.com/fundakol/pytest-jira-xray/blob/master/README.rst Set the JIRA base URL using an environment variable for API communication. ```bash $ export XRAY_API_BASE_URL= ``` -------------------------------- ### evidence module helpers Source: https://context7.com/fundakol/pytest-jira-xray/llms.txt Helper functions to create evidence objects for test reports. These functions base64-encode file data and return a dictionary suitable for attachment. ```APIDOC ## `evidence` module — Attach binary or text artefacts to a test result The `pytest_xray.evidence` module provides helper functions that base64-encode a file or bytes object and return a dict ready to be attached to a test report via the `report.evidences` list. Supported content types: JPEG, PNG, plain text, HTML, JSON, ZIP. ```python # conftest.py import pytest from pytest_xray import evidence @pytest.hookimpl(hookwrapper=True) def pytest_runtest_makereport(item, call): outcome = yield report = outcome.get_result() if report.when == 'call' and report.failed: # Attach a screenshot (JPEG) with open('screenshot.jpeg', 'rb') as f: img_bytes = f.read() jpeg_ev = evidence.jpeg(data=img_bytes, filename='screenshot.jpeg') # Attach a plain-text log snippet log_ev = evidence.text(data='Error: connection timeout after 30s', filename='error.log') # Attach a ZIP archive of test artefacts with open('artefacts.zip', 'rb') as f: zip_ev = evidence.zip(data=f.read(), filename='artefacts.zip') report.evidences = getattr(report, 'evidences', []) report.evidences.extend([jpeg_ev, log_ev, zip_ev]) # All evidence helpers: # evidence.jpeg(data, filename) → {"data": "", "filename": "...", "contentType": "image/jpeg"} # evidence.png(data, filename) → contentType: image/png # evidence.text(data, filename) → contentType: text/plain # evidence.html(data, filename) → contentType: text/html # evidence.json(data, filename) → contentType: application/json # evidence.zip(data, filename) → contentType: application/zip ``` ``` -------------------------------- ### Use with Jira Cloud Source: https://github.com/fundakol/pytest-jira-xray/blob/master/README.rst Add the --cloud flag when using JIRA XRAY Cloud to ensure correct test result formatting. ```bash $ pytest --jira-xray --cloud ``` -------------------------------- ### Store Results in a File Source: https://github.com/fundakol/pytest-jira-xray/blob/master/README.rst Use the --xraypath option to save test results to a JSON file instead of exporting directly to JIRA XRAY. ```bash $ pytest --jira-xray --xraypath=xray.json ``` -------------------------------- ### Write XRAY Results to Local JSON File with FilePublisher Source: https://context7.com/fundakol/pytest-jira-xray/llms.txt Use FilePublisher to serialize XRAY payloads to a local JSON file. The parent directory is created automatically. Returns the absolute file path on success, or raises XrayError on failure. This can also be invoked via CLI using --jira-xray and --xraypath. ```python from pytest_xray.file_publisher import FilePublisher publisher = FilePublisher(filepath='reports/xray-results.json') payload = { 'info': {'startDate': '2024-08-01T08:00:00+0000', 'finishDate': '2024-08-01T08:01:00+0000'}, 'tests': [{'testKey': 'PROJ-101', 'status': 'PASS'}], } saved_path = publisher.publish(payload) print(f'Results saved to: {saved_path}') # Output: Results saved to: reports/xray-results.json # Via CLI (the plugin instantiates FilePublisher automatically): # pytest --jira-xray --xraypath=reports/xray-results.json ``` -------------------------------- ### XrayPublisher class Source: https://context7.com/fundakol/pytest-jira-xray/llms.txt Programmatically publish assembled XRAY JSON payloads to a Jira server via HTTP POST. Supports basic authentication, API key authentication, and OAuth2 for cloud instances. ```APIDOC from pytest_xray.xray_publisher import XrayPublisher, ApiKeyAuth, ClientSecretAuth from pytest_xray.constant import TEST_EXECUTION_ENDPOINT, TEST_EXECUTION_ENDPOINT_CLOUD # ── Basic auth ──────────────────────────────────────────────────────────────── publisher = XrayPublisher( base_url='https://jira.example.com', endpoint=TEST_EXECUTION_ENDPOINT, # '/rest/raven/2.0/import/execution' auth=('ci-user', 'ci-password'), verify=True, ) # ── API Key (Bearer token) auth ─────────────────────────────────────────────── publisher = XrayPublisher( base_url='https://jira.example.com', endpoint=TEST_EXECUTION_ENDPOINT, auth=ApiKeyAuth(api_key='myPersonalAccessToken'), verify='/path/to/ca-bundle.pem', ) # ── Cloud: Client Secret OAuth2 ────────────────────────────────────────────── publisher = XrayPublisher( base_url='https://xray.cloud.getxray.app', endpoint=TEST_EXECUTION_ENDPOINT_CLOUD, # '/api/v2/import/execution' auth=ClientSecretAuth( base_url='https://xray.cloud.getxray.app', client_id='abc123', client_secret='xyz789', ), ) # Publish a manually constructed payload payload = { 'info': { 'startDate': '2024-08-01T08:00:00+0000', 'finishDate': '2024-08-01T08:05:00+0000', 'summary': 'Manual upload example', }, 'tests': [ {'testKey': 'PROJ-101', 'status': 'PASS'}, {'testKey': 'PROJ-102', 'status': 'FAIL', 'comment': 'AssertionError: expected 200 got 500'}, ], } try: execution_id = publisher.publish(payload) print(f'Created/updated Test Execution: {execution_id}') # e.g. 'PROJ-500' except Exception as e: print(f'Upload failed: {e}') ``` -------------------------------- ### Programmatic XRAY Payload Publishing with XrayPublisher Source: https://context7.com/fundakol/pytest-jira-xray/llms.txt Use the `XrayPublisher` class to programmatically send XRAY JSON payloads to a Jira server via HTTP POST. Supports basic authentication, API key (Bearer token) authentication, and Cloud OAuth2 authentication. ```python from pytest_xray.xray_publisher import XrayPublisher, ApiKeyAuth, ClientSecretAuth from pytest_xray.constant import TEST_EXECUTION_ENDPOINT, TEST_EXECUTION_ENDPOINT_CLOUD # ── Basic auth ──────────────────────────────────────────────────────────────── publisher = XrayPublisher( base_url='https://jira.example.com', endpoint=TEST_EXECUTION_ENDPOINT, # '/rest/raven/2.0/import/execution' auth=('ci-user', 'ci-password'), verify=True, ) # ── API Key (Bearer token) auth ─────────────────────────────────────────────── publisher = XrayPublisher( base_url='https://jira.example.com', endpoint=TEST_EXECUTION_ENDPOINT, auth=ApiKeyAuth(api_key='myPersonalAccessToken'), verify='/path/to/ca-bundle.pem', ) # ── Cloud: Client Secret OAuth2 ────────────────────────────────────────────── publisher = XrayPublisher( base_url='https://xray.cloud.getxray.app', endpoint=TEST_EXECUTION_ENDPOINT_CLOUD, # '/api/v2/import/execution' auth=ClientSecretAuth( base_url='https://xray.cloud.getxray.app', client_id='abc123', client_secret='xyz789', ), ) # Publish a manually constructed payload payload = { 'info': { 'startDate': '2024-08-01T08:00:00+0000', 'finishDate': '2024-08-01T08:05:00+0000', 'summary': 'Manual upload example', }, 'tests': [ {'testKey': 'PROJ-101', 'status': 'PASS'}, {'testKey': 'PROJ-102', 'status': 'FAIL', 'comment': 'AssertionError: expected 200 got 500'}, ], } try: execution_id = publisher.publish(payload) print(f'Created/updated Test Execution: {execution_id}') # e.g. 'PROJ-500' except Exception as e: print(f'Upload failed: {e}') ``` -------------------------------- ### Upload Results to Existing Test Execution Source: https://github.com/fundakol/pytest-jira-xray/blob/master/README.rst Use the --execution flag with the test execution ID to upload results to an existing JIRA XRAY test execution. ```bash $ pytest --jira-xray --execution TestExecutionId ``` -------------------------------- ### Jira Personal Access Token Authentication Source: https://github.com/fundakol/pytest-jira-xray/blob/master/README.rst Use the --api-key-auth flag with pytest to authenticate using JIRA Personal Access Tokens (API KEY). ```bash $ pytest --jira-xray --api-key-auth ``` -------------------------------- ### Jira Client Secret Authentication Source: https://github.com/fundakol/pytest-jira-xray/blob/master/README.rst Use the --client-secret-auth flag with pytest to authenticate using JIRA Client ID and Client Secret. ```bash $ pytest --jira-xray --client-secret-auth ``` -------------------------------- ### Attach Evidence to Test Results with pytest-xray Source: https://context7.com/fundakol/pytest-jira-xray/llms.txt Implement the `pytest_runtest_makereport` hook to attach binary or text artifacts like screenshots, logs, or archives to failed test reports. Supported file types include JPEG, PNG, plain text, HTML, JSON, and ZIP. ```python # conftest.py import pytest from pytest_xray import evidence @pytest.hookimpl(hookwrapper=True) def pytest_runtest_makereport(item, call): outcome = yield report = outcome.get_result() if report.when == 'call' and report.failed: # Attach a screenshot (JPEG) with open('screenshot.jpeg', 'rb') as f: img_bytes = f.read() jpeg_ev = evidence.jpeg(data=img_bytes, filename='screenshot.jpeg') # Attach a plain-text log snippet log_ev = evidence.text(data='Error: connection timeout after 30s', filename='error.log') # Attach a ZIP archive of test artefacts with open('artefacts.zip', 'rb') as f: zip_ev = evidence.zip(data=f.read(), filename='artefacts.zip') report.evidences = getattr(report, 'evidences', []) report.evidences.extend([jpeg_ev, log_ev, zip_ev]) # All evidence helpers: # evidence.jpeg(data, filename) → {"data": "", "filename": "...", "contentType": "image/jpeg"} # evidence.png(data, filename) → contentType: image/png # evidence.text(data, filename) → contentType: text/plain # evidence.html(data, filename) → contentType: text/html # evidence.json(data, filename) → contentType: application/json # evidence.zip(data, filename) → contentType: application/zip ``` -------------------------------- ### Upload Results to New Test Execution Source: https://github.com/fundakol/pytest-jira-xray/blob/master/README.rst Run pytest with the --jira-xray flag to upload test results to a new test execution in JIRA XRAY. ```bash $ pytest --jira-xray ``` -------------------------------- ### Handle XRAY Plugin Errors with XrayError Source: https://context7.com/fundakol/pytest-jira-xray/llms.txt Catch XrayError to handle various plugin-related issues such as connection failures or HTTP errors. The exception's message attribute provides a human-readable description of the error encountered during communication with the JIRA service. ```python from pytest_xray.exceptions import XrayError from pytest_xray.xray_publisher import XrayPublisher from pytest_xray.constant import TEST_EXECUTION_ENDPOINT publisher = XrayPublisher( base_url='https://jira.example.com', endpoint=TEST_EXECUTION_ENDPOINT, auth=('user', 'wrong-password'), ) try: publisher.publish({'info': {}, 'tests': []}) except XrayError as exc: # exc.message contains a descriptive string, e.g.: # "HTTPError: Could not post to JIRA service at https://jira.example.com/rest/raven/2.0/import/execution. # Response status code: 401 # Error message from server: Unauthorized" print(f'XRAY error: {exc.message}') ``` -------------------------------- ### Mark pytest tests with JIRA XRAY IDs using @pytest.mark.xray Source: https://context7.com/fundakol/pytest-jira-xray/llms.txt Use the @pytest.mark.xray decorator to associate one or more JIRA test-case IDs with a pytest test function. The optional 'defects' keyword argument can attach defect issue keys to the result. ```python import pytest # Single JIRA test ID @pytest.mark.xray('PROJ-101') def test_login_success(): assert True # Status → PASS → JIRA PROJ-101 marked PASS # Multiple IDs — both receive the same outcome @pytest.mark.xray(['PROJ-102', 'PROJ-103']) def test_checkout_flow(): assert False # Status → FAIL → both PROJ-102 and PROJ-103 marked FAIL # With defect links (always included, independent of outcome) @pytest.mark.xray('PROJ-104', defects=['BUG-55', 'BUG-56']) def test_payment_gateway(): assert True # Uploaded payload fragment: # {"testKey": "PROJ-104", "status": "PASS", "defects": ["BUG-55", "BUG-56"]} ``` -------------------------------- ### Mark Tests with Multiple JIRA IDs Source: https://github.com/fundakol/pytest-jira-xray/blob/master/README.rst Associate a test with multiple JIRA issue IDs by providing a list to the @pytest.mark.xray decorator. Both tests will be marked as failed with the same message if the test fails. ```python # -- FILE: test_example.py import pytest @pytest.mark.xray([ 'JIRA-1', 'JIRA-2' ]) def test_my_process(): assert True ``` -------------------------------- ### Mark Tests with JIRA XRAY IDs Source: https://github.com/fundakol/pytest-jira-xray/blob/master/README.rst Use the pytest.mark.xray decorator to associate tests with JIRA issue IDs. Supports single or multiple IDs. ```python # -- 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 ``` -------------------------------- ### Mutate XRAY Payload with pytest_xray_results Hook Source: https://context7.com/fundakol/pytest-jira-xray/llms.txt Implement the `pytest_xray_results` hook in `conftest.py` to modify the XRAY payload before it is uploaded. This allows for injecting metadata, redacting fields, or adding custom information to the execution details. ```python # conftest.py import os def pytest_xray_results(results, session): """Called with the assembled XRAY payload before uploading.""" # Inject the CI build URL into the execution info block results['info']['description'] = ( f"Build: {os.environ.get('CI_BUILD_URL', 'local')}\n" f"Branch: {os.environ.get('CI_BRANCH', 'unknown')}" ) # Override the executing user results['info']['user'] = 'ci-pipeline' # Example payload structure passed to this hook: # { # "info": { # "startDate": "2024-08-01T08:00:00+0000", # "finishDate": "2024-08-01T08:05:12+0000", # "summary": "Execution of automated tests", # "testPlanKey": "PROJ-300" # }, # "testExecutionKey": "PROJ-500", # only if --execution was supplied # "tests": [ # {"testKey": "PROJ-101", "status": "PASS"}, # {"testKey": "PROJ-102", "status": "FAIL", "comment": "{noformat}...{noformat}"} # ] # } ``` -------------------------------- ### Marking Tests with Defects in Pytest-Jira-Xray Source: https://github.com/fundakol/pytest-jira-xray/blob/master/README.rst Associate defects with tests using the 'defects' argument in the @pytest.mark.xray decorator. Defects are always uploaded to Xray, regardless of test status. ```python # -- FILE: test_example.py import pytest @pytest.mark.xray( 'JIRA-1', defects=['BUG-1', 'BUG-2'] ) def test_with_defects(): assert True ``` -------------------------------- ### Allow Duplicate Test IDs in Pytest-Jira-Xray Source: https://github.com/fundakol/pytest-jira-xray/blob/master/README.rst Use the --allow-duplicate-ids option to run tests even when multiple tests share the same Xray ID. Results are combined, with status determined by individual test outcomes. ```python # -- 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 ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.