Skip to content

Commit

Permalink
feat: add support for custom xfail statuses in pytest
Browse files Browse the repository at this point in the history
- Introduced configuration for custom statuses of xfail-marked tests.
- Default statuses: `skipped` for failed tests and `passed` for successful tests.
- Added methods to read values from `qase.config.json` and environment variables:
  - `QASE_PYTEST_XFAIL_STATUS_XFAIL` for failed xfail tests.
  - `QASE_PYTEST_XFAIL_STATUS_XPASS` for successful xfail tests.
  • Loading branch information
gibiw committed Dec 13, 2024
1 parent 0e30105 commit 573ad23
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
13 changes: 12 additions & 1 deletion qase-python-commons/changelog.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
# [email protected]

## What's new

- Support for custom statuses of xfail-marked tests in pytest.
- Default statuses: `skipped` (failed xfail) and `passed` (successful xfail).
- Configuration values can be set via `qase.config.json` or environment variables:
- `QASE_PYTEST_XFAIL_STATUS_XFAIL`
- `QASE_PYTEST_XFAIL_STATUS_XPASS`

# [email protected]

## What's new

Updated the handling of Gherkin steps to concatenate `keyword` and `name` into the action field when they differ, providing
Updated the handling of Gherkin steps to concatenate `keyword` and `name` into the action field when they differ,
providing
a more descriptive step action.

# [email protected]
Expand Down
2 changes: 1 addition & 1 deletion qase-python-commons/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "qase-python-commons"
version = "3.2.3"
version = "3.2.4"
description = "A library for Qase TestOps and Qase Report"
readme = "README.md"
authors = [{name = "Qase Team", email = "[email protected]"}]
Expand Down
20 changes: 20 additions & 0 deletions qase-python-commons/src/qase/commons/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,19 @@ def __load_file_config(self):
pytest.get("captureLogs")
)

if pytest.get("xfailStatus"):
xfail_status = pytest.get("xfailStatus")

if xfail_status.get("xfail"):
self.config.framework.pytest.xfail_status.set_xfail(
xfail_status.get("xfail")
)

if xfail_status.get("xpass"):
self.config.framework.pytest.xfail_status.set_xpass(
xfail_status.get("xpass")
)

except Exception as e:
self.logger.log("Failed to load config from file", "error")

Expand Down Expand Up @@ -214,5 +227,12 @@ def __load_env_config(self):
if key == 'QASE_PYTEST_CAPTURE_LOGS':
self.config.framework.pytest.set_capture_logs(value)

if key == 'QASE_PYTEST_XFAIL_STATUS_XFAIL':
self.config.framework.pytest.xfail_status.set_xfail(value)

if key == 'QASE_PYTEST_XFAIL_STATUS_XPASS':
self.config.framework.pytest.xfail_status.set_xpass(value)


except Exception as e:
self.logger.log("Failed to load config from env vars {e}", "error")
17 changes: 17 additions & 0 deletions qase-python-commons/src/qase/commons/models/config/framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,28 @@ class Trace(Enum):
failed = "retain-on-failure"


class XFailStatus(BaseModel):
xfail: str = None
xpass: str = None

def __init__(self):
self.xfail = 'skipped'
self.xpass = 'passed'

def set_xfail(self, value: str):
self.xfail = value

def set_xpass(self, value: str):
self.xpass = value


class PytestConfig(BaseModel):
capture_logs: bool = None
xfail_status: XFailStatus = None

def __init__(self):
self.capture_logs = False
self.xfail_status = XFailStatus()

def set_capture_logs(self, capture_logs):
self.capture_logs = QaseUtils.parse_bool(capture_logs)
Expand Down

0 comments on commit 573ad23

Please sign in to comment.