forked from TrueCloudLab/frostfs-testlib
[#5] Remove testlib config file support
In order to make library as flexible as possible we will try to use configuration methods similar to function `logging.dictConfig` from the standard library. So, we won't support configuration file `.neofs-testlib.yaml`, but will allow users to call `configure` method that will load plugins and initialize library components. Signed-off-by: Vladimir Domnich <v.domnich@yadro.com>
This commit is contained in:
parent
c5ff64b3fd
commit
834ddede36
11 changed files with 248 additions and 135 deletions
34
src/neofs_testlib/reporter/allure_handler.py
Normal file
34
src/neofs_testlib/reporter/allure_handler.py
Normal file
|
@ -0,0 +1,34 @@
|
|||
import os
|
||||
from contextlib import AbstractContextManager
|
||||
from textwrap import shorten
|
||||
from typing import Any
|
||||
|
||||
import allure
|
||||
from allure import attachment_type
|
||||
|
||||
from neofs_testlib.reporter.interfaces import ReporterHandler
|
||||
|
||||
|
||||
class AllureHandler(ReporterHandler):
|
||||
"""Handler that stores test artifacts in Allure report."""
|
||||
|
||||
def step(self, name: str) -> AbstractContextManager:
|
||||
name = shorten(name, width=70, placeholder="...")
|
||||
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)
|
||||
|
||||
allure.attach(body, attachment_name, attachment_type)
|
||||
|
||||
def _resolve_attachment_type(self, extension: str) -> attachment_type:
|
||||
"""Try to find matching Allure attachment type by extension.
|
||||
|
||||
If no match was found, default to TXT format.
|
||||
"""
|
||||
extension = extension.lower()
|
||||
return next(
|
||||
(allure_type for allure_type in attachment_type if allure_type.extension == extension),
|
||||
attachment_type.TXT,
|
||||
)
|
Loading…
Add table
Add a link
Reference in a new issue