Skip to content

2. Run two input cases

Continue from 1. Create a project. Use the same xray-demo folder and activated environment.

Map the example to your Jira Test (DEMO-1 is a placeholder). Create test_example.py inside xray-demo, next to .venv. Paste this complete file:

import pytest


@pytest.mark.xray("DEMO-1")
@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 it from xray-demo:

python -m pytest -q test_example.py

Expected summary (timing and progress characters may vary):

2 passed

Here is how the file works:

  • import pytest lets us use pytest's test decorators.
  • The function name starts with test_, so pytest discovers it.
  • @pytest.mark.xray("DEMO-1") maps both cases to the existing Jira Test.
  • parametrize runs the function once for each input pair: first 1, 2, then 2, 3. These two runs are called cases.
  • ids gives those cases readable names. Use names without secrets.
  • assert checks that adding one gives the expected result.

python -m pytest uses pytest from your active environment. -q keeps output short. This first command checks the test itself. The Jira marker is in place, but uploading starts only when --jira-xray is enabled without --xraypath.

Your folder contains:

xray-demo/
  .venv/
  test_example.py

Pytest may also create cache folders. You do not need to edit them.