|
4 | 4 | from allure_commons._core import plugin_manager |
5 | 5 | from allure_commons.types import LabelType, LinkType, ParameterMode |
6 | 6 | from allure_commons.utils import uuid4 |
| 7 | +from allure_commons.utils import format_exception, format_traceback |
7 | 8 | from allure_commons.utils import func_parameters, represent |
8 | 9 |
|
9 | 10 | _TFunc = TypeVar("_TFunc", bound=Callable[..., Any]) |
@@ -216,6 +217,48 @@ def file(self, source, name=None, attachment_type=None, extension=None): |
216 | 217 | attach = Attach() |
217 | 218 |
|
218 | 219 |
|
| 220 | +class GlobalAttach: |
| 221 | + |
| 222 | + def __call__(self, body, name=None, attachment_type=None, extension=None): |
| 223 | + plugin_manager.hook.global_attach_data( |
| 224 | + body=body, |
| 225 | + name=name, |
| 226 | + attachment_type=attachment_type, |
| 227 | + extension=extension, |
| 228 | + ) |
| 229 | + |
| 230 | + def file(self, source, name=None, attachment_type=None, extension=None): |
| 231 | + plugin_manager.hook.global_attach_file( |
| 232 | + source=source, |
| 233 | + name=name, |
| 234 | + attachment_type=attachment_type, |
| 235 | + extension=extension, |
| 236 | + ) |
| 237 | + |
| 238 | + |
| 239 | +global_attach = GlobalAttach() |
| 240 | + |
| 241 | + |
| 242 | +@overload |
| 243 | +def global_error(value: BaseException) -> None: |
| 244 | + ... |
| 245 | + |
| 246 | + |
| 247 | +@overload |
| 248 | +def global_error(value: str, trace: Union[str, None] = None) -> None: |
| 249 | + ... |
| 250 | + |
| 251 | + |
| 252 | +def global_error(value, trace=None): |
| 253 | + message = None |
| 254 | + if isinstance(value, BaseException): |
| 255 | + message = format_exception(type(value), value) |
| 256 | + trace = format_traceback(value.__traceback__) |
| 257 | + else: |
| 258 | + message = value |
| 259 | + plugin_manager.hook.global_error(message=message, trace=trace) |
| 260 | + |
| 261 | + |
219 | 262 | class fixture: |
220 | 263 | def __init__(self, fixture_function, parent_uuid=None, name=None): |
221 | 264 | self._fixture_function = fixture_function |
|
0 commit comments