Skip to content

Commit d143ef1

Browse files
committed
feat: exceptions due to check errors traceback comes from check_result()
1 parent 411f21a commit d143ef1

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

scim2_tester/utils.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import functools
2+
import sys
3+
import types
24
from dataclasses import dataclass
35
from dataclasses import field
46
from enum import Enum
@@ -118,6 +120,18 @@ def __str__(self) -> str:
118120
return self.message
119121

120122

123+
def raise_on_caller(exc: Exception) -> None:
124+
"""Raise exception appearing from caller's frame."""
125+
frame = sys._getframe(2)
126+
tb = types.TracebackType(
127+
tb_next=None,
128+
tb_frame=frame,
129+
tb_lasti=frame.f_lasti,
130+
tb_lineno=frame.f_lineno,
131+
)
132+
raise exc.with_traceback(tb)
133+
134+
121135
@dataclass
122136
class CheckResult:
123137
"""Store a check result."""
@@ -186,7 +200,8 @@ def check_result(
186200
:raises SCIMTesterError: If raise_exceptions is True and status is ERROR or CRITICAL
187201
"""
188202
if context.conf.raise_exceptions and status in (Status.ERROR, Status.CRITICAL):
189-
raise SCIMTesterError(reason or "Check failed", context.conf)
203+
exc = SCIMTesterError(reason or "Check failed", context.conf)
204+
raise_on_caller(exc)
190205

191206
return CheckResult(
192207
status=status,

0 commit comments

Comments
 (0)