Plugin skips (xfail) tests if unresolved Jira issue(s) linked
Project description
pytest-jira-xfail
Plugin skips (xfail) tests linked to unresolved Jira issue(s)
1. Generate your Jira API token
You should have Jira user with API token generated
2. Add PytestJiraHelper to your pytest hook:
import pytest
from pytest_jira_xfail.jira_helper import PytestJiraHelper
@pytest.hookimpl(tryfirst=True)
def pytest_collection_modifyitems(items):
jira = PytestJiraHelper(
jira_url="https://company.atlassian.net",
jira_username="my_jira_user@company.com",
jira_api_token="my_jira_user_api_token",
)
jira.process_linked_jira_issues(items)
3. Link bugs to your tests
from pytest_jira_xfail.annotations import bug
@bug("MP-123")
def test_my_test_fails():
assert False
@bug("MP-124", IndexError)
def test_my_test_broken():
db_records = []
assert db_records[0]
@bug("MP-124")
@bug("MP-124", IndexError)
def test_multiple_exceptions():
db_records = []
assert db_records[0][0] == 'active'
Skip the test entirely (never run it)
By default a test linked to an open bug is still executed and reported as XFAIL
(so an unexpected pass shows up as XPASS). If the bug makes the test unsafe or
pointless to run (e.g. it hangs, corrupts data, or blocks the suite), pass
run=False to skip execution completely while the issue is open. The test is
reported as XFAIL [NOTRUN] and its body is never executed:
from pytest_jira_xfail.annotations import bug
@bug("MP-123", run=False)
def test_not_executed_until_fixed():
assert False # never runs while MP-123 is open
Once the linked issue is resolved, the test runs normally again.
Match the error message, not only the error type
By default a test is treated as XFAIL whenever it raises the expected error
type (raises). If the same error type can be raised for unrelated reasons,
use error_contains to xfail the test only when the raised error message
contains an expected substring (or one of several substrings). If the type
matches but the message does not, the test is reported as a real failure so a
different problem is not silently hidden:
from pytest_jira_xfail.annotations import bug
# XFAIL only if an IndexError with this exact message is raised
@bug("MP-123", IndexError, error_contains="list index out of range")
def test_single_substring():
records = []
assert records[0]
# XFAIL if a KeyError message contains any of the listed substrings
@bug("MP-124", KeyError, error_contains=["'user_id'", "'account_id'"])
def test_multiple_substrings():
payload = {}
assert payload["user_id"]
Matching is case-sensitive by default. Pass case_sensitive=False for
case-insensitive matching:
# Case-sensitive (default): the case must match exactly
@bug("MP-125", ValueError, error_contains="Invalid token")
def test_case_sensitive():
raise ValueError("invalid token") # does NOT match -> reported as a failure
# Case-insensitive: matches regardless of case
@bug("MP-126", ValueError, error_contains="invalid token", case_sensitive=False)
def test_case_insensitive():
raise ValueError("INVALID TOKEN") # matches -> XFAIL
error_contains can be combined with run=False and with multiple @bug
markers (each marker keeps its own expected type, substrings and case option).
Soft assertions (pytest-check)
Tests that fail via soft-assertion libraries such as
pytest-check (check.equal(...),
@check.check_func, ...) are handled correctly: a soft-assertion failure on a
test with an open issue is reported as XFAIL deterministically, regardless of
environment (IDE vs CI) or pytest-xdist. The expected exception type from
raises is still enforced for hard (call-phase) exceptions.
XFAIL message format:
XFAIL The test is skipped because of open bugs:
https://company.atlassian.net/browse/MP-123
4. [Optional] Set custom resolved statuses
By default, only issues with the status "Done" and "Closed" are considered as resolved.
But you can override this and add more statuses, as following:
import pytest
from pytest_jira_xfail.jira_helper import PytestJiraHelper
@pytest.hookimpl(tryfirst=True)
def pytest_collection_modifyitems(items):
jira = PytestJiraHelper(
jira_url="https://company.atlassian.net",
jira_username="my_jira_user@company.com",
jira_api_token="my_jira_user_api_token",
resolved_statuses=["Done", "Closed", "Released", "Declined"]
)
jira.process_linked_jira_issues(items)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pytest_jira_xfail-1.4.1.tar.gz.
File metadata
- Download URL: pytest_jira_xfail-1.4.1.tar.gz
- Upload date:
- Size: 15.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c21fdb17d24b9717edd4bad7a9194b915396418c18c46710330e7fd58fdb97d2
|
|
| MD5 |
7263f2db9519ef044f9b963b4490c33d
|
|
| BLAKE2b-256 |
f766c3e9a02345c978316a3a31e6c9bc2d1ab80a922b9f178df9590d3a37e9ee
|
File details
Details for the file pytest_jira_xfail-1.4.1-py3-none-any.whl.
File metadata
- Download URL: pytest_jira_xfail-1.4.1-py3-none-any.whl
- Upload date:
- Size: 9.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
57904dc755a745c96cf45ce6345cd4309cffb3a2223abae37ce1ca8a622f5fa3
|
|
| MD5 |
5d194d1108dae446d592aad1fde64726
|
|
| BLAKE2b-256 |
3b74cd703c590c5bd3138f505482c967d52d5766848cd8ff915be94baf217ab8
|