2022-08-24 15:01:07 +00:00
|
|
|
from abc import ABC, abstractmethod
|
2023-11-28 09:28:44 +00:00
|
|
|
from contextlib import AbstractContextManager, ContextDecorator
|
2023-05-14 10:43:59 +00:00
|
|
|
from typing import Any, Callable
|
2022-08-24 15:01:07 +00:00
|
|
|
|
|
|
|
|
2022-10-06 10:17:19 +00:00
|
|
|
class ReporterHandler(ABC):
|
|
|
|
"""Interface of handler that stores test artifacts in some reporting tool."""
|
2022-08-24 15:01:07 +00:00
|
|
|
|
|
|
|
@abstractmethod
|
2023-11-28 09:28:44 +00:00
|
|
|
def step(self, name: str) -> AbstractContextManager | ContextDecorator:
|
2022-10-05 09:14:51 +00:00
|
|
|
"""Register a new step in test execution.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
name: Name of the step.
|
2022-08-24 15:01:07 +00:00
|
|
|
|
2022-10-05 09:14:51 +00:00
|
|
|
Returns:
|
|
|
|
Step context.
|
2022-08-24 15:01:07 +00:00
|
|
|
"""
|
|
|
|
|
2023-05-14 10:43:59 +00:00
|
|
|
@abstractmethod
|
|
|
|
def step_decorator(self, name: str) -> Callable:
|
|
|
|
"""A step decorator from reporter.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
name: Name of the step.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
decorator for the step
|
|
|
|
"""
|
|
|
|
|
2022-08-24 15:01:07 +00:00
|
|
|
@abstractmethod
|
|
|
|
def attach(self, content: Any, file_name: str) -> None:
|
2022-10-05 09:14:51 +00:00
|
|
|
"""Attach specified content with given file name to the test report.
|
2022-08-24 15:01:07 +00:00
|
|
|
|
2022-10-05 09:14:51 +00:00
|
|
|
Args:
|
|
|
|
content: Content to attach. If content value is not a string, it will be
|
|
|
|
converted to a string.
|
|
|
|
file_name: File name of attachment.
|
2022-08-24 15:01:07 +00:00
|
|
|
"""
|