forked from TrueCloudLab/frostfs-testlib
Move shared code to testlib
Signed-off-by: Andrey Berezin <a.berezin@yadro.com>
This commit is contained in:
parent
d97a02d1d3
commit
997e768e92
69 changed files with 9213 additions and 64 deletions
|
@ -1,7 +1,7 @@
|
|||
import os
|
||||
from contextlib import AbstractContextManager
|
||||
from textwrap import shorten
|
||||
from typing import Any
|
||||
from typing import Any, Callable
|
||||
|
||||
import allure
|
||||
from allure import attachment_type
|
||||
|
@ -16,6 +16,9 @@ class AllureHandler(ReporterHandler):
|
|||
name = shorten(name, width=70, placeholder="...")
|
||||
return allure.step(name)
|
||||
|
||||
def step_decorator(self, name: str) -> Callable:
|
||||
return allure.step(name)
|
||||
|
||||
def attach(self, body: Any, file_name: str) -> None:
|
||||
attachment_name, extension = os.path.splitext(file_name)
|
||||
attachment_type = self._resolve_attachment_type(extension)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from abc import ABC, abstractmethod
|
||||
from contextlib import AbstractContextManager
|
||||
from typing import Any
|
||||
from typing import Any, Callable
|
||||
|
||||
|
||||
class ReporterHandler(ABC):
|
||||
|
@ -17,6 +17,17 @@ class ReporterHandler(ABC):
|
|||
Step context.
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
def step_decorator(self, name: str) -> Callable:
|
||||
"""A step decorator from reporter.
|
||||
|
||||
Args:
|
||||
name: Name of the step.
|
||||
|
||||
Returns:
|
||||
decorator for the step
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
def attach(self, content: Any, file_name: str) -> None:
|
||||
"""Attach specified content with given file name to the test report.
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
from contextlib import AbstractContextManager, contextmanager
|
||||
from functools import wraps
|
||||
from types import TracebackType
|
||||
from typing import Any, Optional
|
||||
from typing import Any, Callable, Optional
|
||||
|
||||
from frostfs_testlib.plugins import load_plugin
|
||||
from frostfs_testlib.reporter.interfaces import ReporterHandler
|
||||
|
@ -45,6 +46,32 @@ class Reporter:
|
|||
handler_class = load_plugin("frostfs.testlib.reporter", handler_config["plugin_name"])
|
||||
self.register_handler(handler_class())
|
||||
|
||||
def step_deco(self, name: str) -> Callable:
|
||||
"""Register a new step in test execution in a decorator fashion.
|
||||
|
||||
To note: the actual decoration with handlers is happening during target function call time.
|
||||
|
||||
Args:
|
||||
name: Name of the step.
|
||||
|
||||
Returns:
|
||||
decorated function
|
||||
"""
|
||||
|
||||
def deco(func):
|
||||
@wraps(func)
|
||||
def wrapper(*a, **kw):
|
||||
resulting_func = func
|
||||
for handler in self.handlers:
|
||||
decorator = handler.step_decorator(name)
|
||||
resulting_func = decorator(resulting_func)
|
||||
|
||||
return resulting_func(*a, **kw)
|
||||
|
||||
return wrapper
|
||||
|
||||
return deco
|
||||
|
||||
def step(self, name: str) -> AbstractContextManager:
|
||||
"""Register a new step in test execution.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue