Metadata-Version: 2.4
Name: pytest-jira-xray-plus
Version: 1.0.0
Summary: Create and reuse independent Jira Xray Generic Tests for pytest parameter cases
Author-email: Lukasz Fundakowski <fundakol@yahoo.com>
License-Expression: Apache-2.0
Project-URL: Documentation, https://matusowskymichael.github.io/pytest-Jira-xray-plus/
Project-URL: Repository, https://github.com/matusowskymichael/pytest-Jira-xray-plus
Project-URL: Issues, https://github.com/matusowskymichael/pytest-Jira-xray-plus/issues
Project-URL: Upstream, https://github.com/fundakol/pytest-jira-xray
Keywords: pytest, JIRA, XRAY
Classifier: Development Status :: 5 - Production/Stable
Classifier: Framework :: Pytest
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Requires-Python: >=3.12
Description-Content-Type: text/markdown
License-File: LICENSE
License-File: NOTICE
Requires-Dist: pytest<10,>=9.1.1
Requires-Dist: requests<3,>=2.34.2
Dynamic: license-file

# pytest-Jira-xray-plus

[![PyPI version snapshot](https://matusowskymichael.github.io/pytest-Jira-xray-plus/status/pypi.svg)](https://pypi.org/project/pytest-jira-xray-plus/)
[![Tested Python versions](https://matusowskymichael.github.io/pytest-Jira-xray-plus/status/python.svg)](https://github.com/matusowskymichael/pytest-Jira-xray-plus/actions/workflows/tests.yml)
[![Licence](https://matusowskymichael.github.io/pytest-Jira-xray-plus/status/license.svg)](https://github.com/matusowskymichael/pytest-Jira-xray-plus/blob/main/LICENSE)
[![Tests](https://github.com/matusowskymichael/pytest-Jira-xray-plus/actions/workflows/tests.yml/badge.svg?branch=main&event=push)](https://github.com/matusowskymichael/pytest-Jira-xray-plus/actions/workflows/tests.yml)
[![Documentation build](https://github.com/matusowskymichael/pytest-Jira-xray-plus/actions/workflows/docs.yml/badge.svg?branch=main&event=push)](https://matusowskymichael.github.io/pytest-Jira-xray-plus/)
[![Measured plugin line coverage](https://matusowskymichael.github.io/pytest-Jira-xray-plus/coverage/coverage.svg)](https://matusowskymichael.github.io/pytest-Jira-xray-plus/coverage/)

Create a separate **Jira Xray Generic Test issue for every pytest parameter case**,
reuse that issue on later runs, and publish each case's independent result into
an existing Test Execution. Jira with the Xray app is required for the integration.
No comments or native iteration rows substitute for separate Test issues.

[Beginner quick start](#1-create-a-project) · [Offline plan](#3-preview-the-jiraxray-import)
· [Create and upload](#4-authenticate-and-publish-to-jiraxray) · [Troubleshooting](#troubleshooting)

This guide targets **1.0.0**. Check [PyPI release availability](https://pypi.org/project/pytest-jira-xray-plus/#history)
before installing the pinned version. It does not describe 0.1.13. For an unpublished
candidate, install its reviewed wheel. Exact-version limitations are recorded in
[the compatibility document](https://github.com/matusowskymichael/pytest-Jira-xray-plus/blob/main/docs/SERVER-COMPATIBILITY.md).

## Jira/Xray prerequisites

- Python 3.12+ and pytest 9.1.1–9.x. Use a clean environment; upstream
  `pytest-jira-xray` installs the same `pytest_xray` module and plugin entry point.
- Jira Server/DC with Xray. Target: Generic Tests on **Xray 8.5.3-j10**. This exact
  installed version has not been tested against a live server. Cloud creation,
  custom Automatic type mapping, native iterations and datasets are unsupported.
- An authorized project and existing Test Execution. An administrator supplies
  the Test and Test Execution issue type IDs, Xray Test Type custom field ID,
  Generic Test Definition field ID, and required creation fields. IDs vary per site.
- Existing credentials with Browse Projects, Create Issues (only for creation),
  Edit Issues and Xray import permissions. Project permission checks cannot prove
  all Xray-specific authorization; an import failure remains a failure.
- One authoritative durable case map, shared by every creator of this suite.
  Serialize creators across machines. A local exclusive lock cannot enforce
  uniqueness across independent map copies or server nodes. Never run independent
  writers under the same identity namespace.

The offline plan needs no credentials or server and validates no server settings.
Only explicit `--xray-create-tests` permits creating Tests. `--jira-xray` requests
upload; selecting `--xray-case-config` alone does not grant creation permission.
Existing Jira Test specifications are never edited or deleted by this workflow.

## 1. Create a project

Create `xray-demo`, open a terminal there, then create a virtual environment:

```sh
python -m venv .venv
```

Activate it with `source .venv/bin/activate` on Linux/macOS or
`.venv\Scripts\Activate.ps1` in PowerShell. After 1.0.0 is published:

```sh
python -m pip install pytest-jira-xray-plus==1.0.0 pytest-xdist pytest-rerunfailures
python -m pytest --help
```

During candidate validation install the reviewed wheel instead. Never install
both forks in one environment. If both were installed, create a fresh environment.

## 2. Run two input cases

Save this as `test_example.py`. Each explicit ID identifies one stable logical
case. Keep IDs stable across reruns and change them when the meaning of a case
changes. Do not put passwords, personal data or other secrets in IDs.

<!-- tutorial:passing -->
```python
import pytest

@pytest.mark.parametrize('value, expected', [(1, 2), (2, 3)], ids=['one-plus-one', 'two-plus-one'])
def test_add_one(value, expected):
    assert value + 1 == expected
```

<!-- run:basic -->
```sh
python -m pytest -q
```

Expect `2 passed`. No Jira action occurs. Do not apply a shared `xray` key marker
to these cases. The automatic workflow rejects manual key markers rather than
silently combining cases under one Test.

## 3. Preview the Jira/Xray import

Save this synthetic configuration as `case-config.json`. Replace the placeholder
IDs with administrator-confirmed values before uploading. `namespace` identifies
this suite within the Jira project; keep it stable and unique across repositories.

<!-- config:cases -->
```json
{
  "project": "DEMO",
  "namespace": "example-suite",
  "test_issue_type": "100",
  "execution_issue_type": "101",
  "test_type_field": "customfield_10",
  "definition_field": "customfield_11",
  "extra_fields": {}
}
```

<!-- run:plan -->
```sh
python -m pytest -q --xray-case-config=case-config.json --xray-case-plan=plan.json
```

<!-- run:inspect_plan -->
```sh
python -m json.tool plan.json
```

The plan contains two different SHA-256 identities, two proposed Generic Test
creation documents and independent PASS results. It is **not an Xray import file**:
no Jira keys exist yet. Summaries and definitions use opaque identities, not raw
parameter values, node IDs or case IDs. Hashing is not encryption; predictable
inputs can be guessed. `extra_fields` is copied as supplied and may be sensitive.

<!-- run:collect_plan -->
```sh
python -m pytest --collect-only -q --xray-case-config=case-config.json --xray-case-plan=collection.json
```

To identify just one case before looking up its eventual Jira key:

<!-- run:singleton -->
```sh
python -m pytest -q -k one-plus-one --xray-case-config=case-config.json --xray-case-plan=singleton.json
```

<!-- run:inspect_singleton -->
```sh
python -m json.tool singleton.json
```

Record the sole `cases[0].identity`. After the authorized online run below, find
that exact identity in `case-map.json` under `cases`; its confirmed `key` is the
separate Generic Test issue for this case. The plan itself contains no Jira key.

Collect-only records NOT_RUN without executing tests or using the network. Plans
are local output files; use access controls appropriate to their contents.

## 4. Authenticate and publish to Jira/Xray

Use an existing authorized test project first. Set environment variables through
your shell's secure prompt or CI secret store; never commit credentials:

```sh
export XRAY_API_BASE_URL=https://jira.example.invalid
read -rsp 'Existing Jira PAT: ' XRAY_API_KEY
export XRAY_API_KEY
```

The hostname is a placeholder. Keep TLS certificate verification enabled and use
trusted certificates. The API key option uses Jira's existing PAT authentication.
Basic authentication instead uses `XRAY_API_USER` and `XRAY_API_PASSWORD` and omits
`--api-key-auth`; never put secret values on the command line.

After confirming configuration and exclusive writer ownership:

```sh
python -m pytest -q --xray-case-config=case-config.json --xray-case-map=case-map.json --jira-xray --api-key-auth --execution=DEMO-1 --xray-create-tests --xray-single-writer
```

The controller checks project, execution type, permissions and creation metadata;
then reuses exact matching Tests or creates missing Tests. It imports each result
by its confirmed key into `DEMO-1`. The execution itself must already exist.
Keep `case-map.json` durable between runs. To reuse only, omit
`--xray-create-tests` and `--xray-single-writer`. A missing Test then fails closed.
The single-writer flag is an explicit operating assertion, not a distributed lock.

Inspect the map locally with `python -m json.tool case-map.json`. For the synthetic
example, the two identities might resolve to `DEMO-101` and `DEMO-102`; actual keys
come from Jira and must never be inferred from this example. Temporarily change
the second expected value to `99` as shown in section 7, then run use-only:

```sh
python -m pytest -q --xray-case-config=case-config.json --xray-case-map=case-map.json --jira-xray --api-key-auth --execution=DEMO-1
```

Expect pytest exit 1 and two independent Test Runs: the first case's confirmed key
has PASS, the second has FAIL. Repeat the same use-only command: both keys remain
unchanged and no Test is created. This command imports results online; the
repository's installed tutorial verifies it only against a loopback synthetic
server. Inspect the selected Test Execution in your authorized environment to
check its Test Runs; local fixture success is not live Xray validation.


A lost creation response leaves a pending record. Subsequent runs may reconcile
one exact existing Test; zero or multiple matches block further creation. Do not
remove the map or its pending entry to force a retry. Have an authorized operator
reconcile the outcome and search-index visibility first. No automatic POST retries
occur. Import failure may have changed the execution; inspect it before rerunning.

## 5. Audit independent cases locally

The plan shows one record per selected case without using Jira. For detailed local
pytest phases, use the separate audit report and redact identities:

<!-- run:audit -->
```sh
python -m pytest -q --xray-case-report=cases.json --xray-case-redact-identities
```

<!-- run:inspect_audit -->
```sh
python -m json.tool cases.json
```

This records phase outcomes, retries and worker IDs. Its per-run aliases are not
the stable mapping identities. Do not combine this separate audit mode with case
creation in the same command; use the plan for the automatic workflow.

## 6. Choose audit report contents

Raw audit reports expose node IDs, which may contain parameter data. Value capture
is separate, explicit and potentially sensitive:

<!-- run:values -->
```sh
python -m pytest -q --xray-case-report=values.json --xray-case-values
```

Do not use raw values with private input data. Generation plans never contain raw
parameter values automatically. Hook-added evidence and custom fields are your
responsibility; they are not automatically redacted.

## 7. Diagnose a failing case

Temporarily replace the second expected value with `99`:

<!-- tutorial:failing -->
```python
import pytest

@pytest.mark.parametrize('value, expected', [(1, 2), (2, 99)], ids=['one-plus-one', 'two-plus-one'])
def test_add_one(value, expected):
    assert value + 1 == expected
```

<!-- run:failure -->
```sh
python -m pytest -q --xray-case-config=case-config.json --xray-case-plan=failure.json
```

Expect exit code 1 and separate PASS/FAIL cases. Successful setup/teardown cannot
turn a failure into PASS. Skips are ABORTED; expected failure is FAIL, non-strict
unexpected pass is PASS, strict unexpected pass and fixture errors are FAIL.
Any failed rerun attempt keeps FAIL. Incomplete collection or a crashed worker
withholds all creation/import. Transport or mapping failures produce exit code 3.
Restore the passing example before continuing.

<!-- tutorial:restored -->
```python
import pytest

@pytest.mark.parametrize('value, expected', [(1, 2), (2, 3)], ids=['one-plus-one', 'two-plus-one'])
def test_add_one(value, expected):
    assert value + 1 == expected
```

## 8. Preserve mapping and recovery evidence

Back up the authoritative case map securely. Each record is `pending` or
`confirmed`; it is bound to the configured server and fields. Do not copy maps
between unrelated servers, change their binding, or assign one Test key to two
identities. A crash can leave a `.lock` file: confirm the owning process stopped
and reconcile pending outcomes before manually removing a stale lock. The plugin
never breaks locks automatically. Plans are not substitutes for the durable map.

## Optional recipes

### Parallel tests and retries

<!-- run:parallel -->
```sh
python -m pytest -q -n 2 --xray-case-config=case-config.json --xray-case-plan=workers.json
```

<!-- run:selection -->
```sh
python -m pytest -q -k one-plus-one --xray-case-config=case-config.json --xray-case-plan=selected.json
```

Workers run tests and report hashed identities. Only the controller locks the map,
reads credentials, creates issues and imports results. Different worker collections
or incomplete execution block publication. Do not run two independent controllers
with separate map copies. Reruns reuse the case identity; a failed attempt remains FAIL.

### Associate one function with multiple Tests

Automatic case generation assigns exactly one Test per combination and rejects
manual `xray` markers. Ordinary manual mapping remains available for existing
one-to-one cases: `@pytest.mark.xray('DEMO-101')` with `--jira-xray --execution=DEMO-1`
(or the complete command `python -m pytest --jira-xray --xraypath=results.json`
for offline export). Never share a key between cases.
Multiple distinct manual keys can represent the same ordinary test where intended;
this does not enable parameter aggregation. Manual mode does not create Tests.

For a complete offline manual example, temporarily replace `test_example.py`:

<!-- tutorial:manual -->
```python
import pytest

@pytest.mark.xray('DEMO-101')
def test_manual():
    assert True
```

<!-- run:manual_export -->
```sh
python -m pytest --jira-xray --xraypath=results.json
```

This writes manual Xray JSON without contacting Jira. `--xraypath` alone does
not enable the publisher. Restore the two-case example for automatic mapping.

## Advanced: customize the export with hooks

`pytest_xray_results(results, session)` runs before import. In automatic mode it
may add comments, defects or evidence, but must preserve the execution, ordered
Test keys and supported statuses and must not inject `testInfo`. Comment byte
limits still apply. Hooks are trusted local code and can expose sensitive data;
no raw failure text is added automatically in this mode. Manual-mode report
attachments use the existing `report.evidences` list of evidence dictionaries.

## All package options

| Option | Purpose and network behavior |
| --- | --- |
| `--xray-case-config=PATH` | Select independent automatic Generic Test mapping |
| `--xray-case-plan=PATH` | Offline plan, mutually exclusive with upload/creation |
| `--xray-case-map=PATH` | Authoritative durable mapping for online runs |
| `--xray-create-tests` | Explicit permission to create missing Tests |
| `--xray-single-writer` | Assert serialized creation with a shared map |
| `--jira-xray` | Online upload when configured; manual offline export requires `--xraypath` too |
| `--execution=KEY` | Existing Test Execution; required in automatic mode |
| `--api-key-auth` | Existing Jira PAT from the environment |
| `--xray-case-report=PATH` | Separate offline phase audit |
| `--xray-case-redact-identities` | Per-run aliases in the audit |
| `--xray-case-values` | Explicit scalar parameter capture in the audit |
| `--xray-comment-limit=N` | UTF-8 comment limit, default 32000, minimum 256 |
| `--xraypath=PATH` | Offline manual JSON export, enabled together with `--jira-xray` |
| `--testplan`, `--add-captures`, `--xray-parameter-details`, `--xray-full-report` | Manual mapping only |
| `--cloud`, `--client-secret-auth` | Existing manual transport only; unsupported for automatic creation |

**Warning:** `--jira-xray` without an offline output option can publish live
results when configured. `--xray-case-plan` and standalone `--xray-case-report`
are offline; neither grants creation permission.

`--allow-duplicate-ids` is not an aggregation compatibility mode in 1.0.0.
See `python -m pytest --help` for exact syntax. Options from different workflows
must not silently override one another.

## Authentication and execution settings

`XRAY_API_BASE_URL` includes any Jira context path. Existing PAT authentication
uses `XRAY_API_KEY`; Basic uses `XRAY_API_USER` and `XRAY_API_PASSWORD`.
Automatic creation requires verified TLS; redirects are not followed and HTTP
is allowed only for local loopback fixtures. No credentials are needed for plans.
No credentials, response bodies or raw case IDs belong in diagnostics.

## Result rules and compatibility

Automatic identity hashes a versioned tuple of project, suite namespace, relative
logical test path/name and structured parameter identity. For parametrized tests,
that structure contains parameter names in pytest insertion order, sorted groups
of axis names (names within each group are also sorted), and pytest's ordered
per-axis ID components (`callspec._idlist`). Non-parametrized tests use null.
It is not just the displayed joined case ID. Renaming parameters, changing their
order within a parametrization, or reordering stacked axes can create new
identities and therefore new Tests when creation is authorized. Changing project,
namespace, logical test path/name or IDs also changes identity. Keep these inputs
stable for the same logical case, with unique IDs for distinct cases.

For example, this test has ordered parameters `['y', 'x']`, sorted axes
`[['x'], ['y']]` and ordered ID components `['why', 'ex']`:

```python
@pytest.mark.parametrize('x', [1], ids=['ex'])
@pytest.mark.parametrize('y', [2], ids=['why'])
def test_pair(x, y):
    assert x < y
```

Swapping the two decorators changes the ordered parameters to `['x', 'y']` and
ID components to `['ex', 'why']`, producing a different identity even though the
values and assertion are unchanged. Likewise, changing `'x,y'` to `'y,x'` in one
axis changes identity; reordering rows together with their stable IDs does not.
The initial supported automatic subset is static `pytest.mark.parametrize` with
explicit unique string IDs on every axis (including `pytest.param(..., id=...)`
and parametrized fixtures with explicit IDs).
Default positional IDs, callable ID generators, dynamic `metafunc.parametrize`
are currently rejected rather than guessed.

Search requires exactly one matching identity label and verifies project, issue
type, Generic type and full definition. Missing/moved/modified mapped issues fail;
no replacement or overwrite is automatic. Jira search visibility is not a uniqueness
constraint. Cross-host concurrency and Xray-specific permissions cannot be proven
by this plugin. No live compatibility claim is made for Xray 8.5.3-j10.

## Troubleshooting

- Missing option: check installed version, active interpreter and fork conflict.
- Metadata rejected: confirm configured numeric issue/field IDs, Generic option,
  required fields and create screen. Custom Automatic is not assumed Generic.
- Pending map: reconcile uncertain creation; do not delete the record to retry.
- Lock exists: stop competing writers and verify ownership before recovery.
- HTTP/auth/permission/TLS errors: correct the authorized configuration; never
  disable verification or blindly replay a write.
- Offline export error: diagnose the destination path. No Jira connection occurs.
- Test failure: pytest returns 1 even when its result was successfully imported.
- Partial import or lost response: the execution may have changed. Verify it before
  deciding whether to rerun; no automatic retry or rollback is implemented.

## Project and development

[Repository](https://github.com/matusowskymichael/pytest-Jira-xray-plus) ·
[API decisions](https://github.com/matusowskymichael/pytest-Jira-xray-plus/blob/main/docs/API.md) ·
[Release readiness](https://github.com/matusowskymichael/pytest-Jira-xray-plus/blob/main/docs/RELEASE-READINESS.md).
Tests use synthetic fixtures; no workplace server or data. Maintainers run the
repository harness, installed-wheel tutorial and independent review before release.
Apache-2.0; upstream attribution is retained in NOTICE.
