Skip to content

Arm backend: improve common.parameterize decorator #9358

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 20, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions backends/arm/test/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,20 @@ def get_u85_compile_spec_unbuilt(
)
"""Xfails a test if Corsone320 FVP is not installed, or if the executor runner is not built"""

xfail_type = str | tuple[str, type[Exception]]


def parametrize(
arg_name: str, test_data: dict[str, Any], xfails: dict[str, str] = None
arg_name: str,
test_data: dict[str, Any],
xfails: dict[str, xfail_type] | None = None,
):
"""
Custom version of pytest.mark.parametrize with some syntatic sugar and added xfail functionality
- test_data is expected as a dict of (id, test_data) pairs
- alllows to specifiy a dict of (id, failure_reason) pairs to mark specific tests as xfail
- alllows to specifiy a dict of (id, failure_reason) pairs to mark specific tests as xfail.
Failure_reason can be str, type[Exception], or tuple[str, type[Exception]].
Strings set the reason for failure, the exception type sets expected error.
"""
if xfails is None:
xfails = {}
Expand All @@ -208,8 +214,21 @@ def decorator_func(func):
pytest_testsuite = []
for id, test_parameters in test_data.items():
if id in xfails:
xfail_info = xfails[id]
reason = ""
raises = None
if isinstance(xfail_info, str):
reason = xfail_info
elif isinstance(xfail_info, tuple):
reason, raises = xfail_info
else:
raise RuntimeError(
"xfail info needs to be str, or tuple[str, type[Exception]]"
)
pytest_param = pytest.param(
test_parameters, id=id, marks=pytest.mark.xfail(reason=xfails[id])
test_parameters,
id=id,
marks=pytest.mark.xfail(reason=reason, raises=raises, strict=True),
)
else:
pytest_param = pytest.param(test_parameters, id=id)
Expand Down
Loading