Skip to content

Commit cbf4f70

Browse files
committed
Arm backend: improve common.parameterize decorator
- Set xfails to strict to detect if failing tests start working - Add possibility to pass expected Error type Signed-off-by: Erik Lundell <erik.lundell@arm.com> Change-Id: I594e6ade5e57ad7024457934bad45a3c1fa5c4fc
1 parent e86c9c9 commit cbf4f70

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

backends/arm/test/common.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,20 @@ def get_u85_compile_spec_unbuilt(
167167
)
168168
"""Skips a test if Corsone320 FVP is not installed, or if the executor runner is not built."""
169169

170+
xfail_type = str | tuple[str, type[Exception]]
171+
170172

171173
def parametrize(
172-
arg_name: str, test_data: dict[str, Any], xfails: dict[str, str] = None
174+
arg_name: str,
175+
test_data: dict[str, Any],
176+
xfails: dict[str, xfail_type] | None = None,
173177
):
174178
"""
175179
Custom version of pytest.mark.parametrize with some syntatic sugar and added xfail functionality
176180
- test_data is expected as a dict of (id, test_data) pairs
177-
- alllows to specifiy a dict of (id, failure_reason) pairs to mark specific tests as xfail
181+
- alllows to specifiy a dict of (id, failure_reason) pairs to mark specific tests as xfail.
182+
Failure_reason can be str, type[Exception], or tuple[str, type[Exception]].
183+
Strings set the reason for failure, the exception type sets expected error.
178184
"""
179185
if xfails is None:
180186
xfails = {}
@@ -184,8 +190,21 @@ def decorator_func(func):
184190
pytest_testsuite = []
185191
for id, test_parameters in test_data.items():
186192
if id in xfails:
193+
xfail_info = xfails[id]
194+
reason = ""
195+
raises = None
196+
if isinstance(xfail_info, str):
197+
reason = xfail_info
198+
elif isinstance(xfail_info, tuple):
199+
reason, raises = xfail_info
200+
else:
201+
raise RuntimeError(
202+
"xfail info needs to be str, or tuple[str, type[Exception]]"
203+
)
187204
pytest_param = pytest.param(
188-
test_parameters, id=id, marks=pytest.mark.xfail(reason=xfails[id])
205+
test_parameters,
206+
id=id,
207+
marks=pytest.mark.xfail(reason=reason, raises=raises, strict=True),
189208
)
190209
else:
191210
pytest_param = pytest.param(test_parameters, id=id)

0 commit comments

Comments
 (0)