Skip to content

Commit 5cd973c

Browse files
authored
Arm backend: Improve common.parameterize decorator (#9358)
- Set xfails to strict to detect if failing tests start working - Add possibility to pass expected Error type Signed-off-by: Erik Lundell <[email protected]>
1 parent 4e1d2e5 commit 5cd973c

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
@@ -224,14 +224,20 @@ def get_u85_compile_spec_unbuilt(
224224
)
225225
"""Xfails a test if Corsone320 FVP is not installed, or if the executor runner is not built"""
226226

227+
xfail_type = str | tuple[str, type[Exception]]
228+
227229

228230
def parametrize(
229-
arg_name: str, test_data: dict[str, Any], xfails: dict[str, str] = None
231+
arg_name: str,
232+
test_data: dict[str, Any],
233+
xfails: dict[str, xfail_type] | None = None,
230234
):
231235
"""
232236
Custom version of pytest.mark.parametrize with some syntatic sugar and added xfail functionality
233237
- test_data is expected as a dict of (id, test_data) pairs
234-
- alllows to specifiy a dict of (id, failure_reason) pairs to mark specific tests as xfail
238+
- alllows to specifiy a dict of (id, failure_reason) pairs to mark specific tests as xfail.
239+
Failure_reason can be str, type[Exception], or tuple[str, type[Exception]].
240+
Strings set the reason for failure, the exception type sets expected error.
235241
"""
236242
if xfails is None:
237243
xfails = {}
@@ -241,8 +247,21 @@ def decorator_func(func):
241247
pytest_testsuite = []
242248
for id, test_parameters in test_data.items():
243249
if id in xfails:
250+
xfail_info = xfails[id]
251+
reason = ""
252+
raises = None
253+
if isinstance(xfail_info, str):
254+
reason = xfail_info
255+
elif isinstance(xfail_info, tuple):
256+
reason, raises = xfail_info
257+
else:
258+
raise RuntimeError(
259+
"xfail info needs to be str, or tuple[str, type[Exception]]"
260+
)
244261
pytest_param = pytest.param(
245-
test_parameters, id=id, marks=pytest.mark.xfail(reason=xfails[id])
262+
test_parameters,
263+
id=id,
264+
marks=pytest.mark.xfail(reason=reason, raises=raises, strict=True),
246265
)
247266
else:
248267
pytest_param = pytest.param(test_parameters, id=id)

0 commit comments

Comments
 (0)