Skip to content

Commit 7359599

Browse files
authored
allure library (fixes #257 closes #258 via #262)
1 parent 7285adf commit 7359599

File tree

16 files changed

+192
-16
lines changed

16 files changed

+192
-16
lines changed

allure-robotframework/setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ def read(fname):
3131
description="Allure Robot Framework integration",
3232
license="Apache-2.0",
3333
keywords="allure reporting robotframework",
34-
packages=['allure_robotframework'],
35-
package_dir={"allure_robotframework": "src"},
34+
packages=['allure_robotframework', 'AllureLibrary'],
35+
package_dir={"allure_robotframework": "src/listener", 'AllureLibrary': 'src/library'},
3636
install_requires=install_requires,
3737
py_modules=['allure_robotframework'],
3838
url="https://github.com/allure-framework/allure-python",

allure-robotframework/src/__init__.py

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from .allure_library import attach, attach_file
2+
3+
__all__ = ['attach', 'attach_file']
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import allure
2+
3+
4+
__all__ = ['attach', 'attach_file']
5+
6+
7+
def _attachment_type(name):
8+
try:
9+
return allure.attachment_type[name]
10+
except KeyError:
11+
return name
12+
13+
14+
def attach(data, name=None, attachment_type=None, extension=None):
15+
allure.attach(data, name=name, attachment_type=_attachment_type(attachment_type), extension=extension)
16+
17+
18+
def attach_file(source, name=None, attachment_type=None, extension=None):
19+
allure.attach.file(source, name=name, attachment_type=_attachment_type(attachment_type), extension=extension)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from allure_robotframework.robot_listener import allure_robotframework
2+
3+
__all__ = ['allure_robotframework']
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import allure_commons
2+
from allure_commons.utils import uuid4
3+
4+
5+
class AllureListener(object):
6+
def __init__(self, logger):
7+
self.logger = logger
8+
9+
@allure_commons.hookimpl
10+
def attach_data(self, body, name, attachment_type, extension):
11+
self.logger.attach_data(uuid4(), body, name=name, attachment_type=attachment_type, extension=extension)
12+
13+
@allure_commons.hookimpl
14+
def attach_file(self, source, name, attachment_type, extension):
15+
self.logger.attach_file(uuid4(), source, name=name, attachment_type=attachment_type, extension=extension)

allure-robotframework/src/listener.py renamed to allure-robotframework/src/listener/robot_listener.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
from allure_commons.utils import now, uuid4, md5, host_tag
88
from allure_commons.logger import AllureFileLogger
99
from allure_commons.types import AttachmentType, LabelType, LinkType
10-
from allure_commons import plugin_manager
1110
from allure_commons.utils import platform_label
1211
from robot.libraries.BuiltIn import BuiltIn
13-
from allure_robotframework.constants import RobotKeywordType, RobotLogLevel
12+
from allure_robotframework.types import RobotKeywordType, RobotLogLevel
1413
from allure_robotframework import utils
1514
import os
15+
from allure_robotframework.allure_listener import AllureListener
16+
import allure_commons
1617

1718

1819
# noinspection PyPep8Naming
@@ -23,14 +24,17 @@ class allure_robotframework(object):
2324
FAIL_MESSAGE_FORMAT = '{full_message}<p style="color: red"><b>[{level}]</b> {message}</p>'
2425

2526
def __init__(self, logger_path=DEFAULT_OUTPUT_PATH):
26-
self.reporter = AllureReporter()
27-
self.logger = AllureFileLogger(logger_path)
2827
self.stack = []
2928
self.items_log = {}
3029
self.pool_id = None
3130
self.links = OrderedDict()
32-
plugin_manager.register(self.reporter)
33-
plugin_manager.register(self.logger)
31+
32+
self.reporter = AllureReporter()
33+
self.listener = AllureListener(self.reporter)
34+
self.logger = AllureFileLogger(logger_path)
35+
36+
allure_commons.plugin_manager.register(self.logger)
37+
allure_commons.plugin_manager.register(self.listener)
3438

3539
def start_suite(self, name, attributes):
3640
if not self.pool_id:
@@ -174,3 +178,8 @@ def set_suite_link(self, metadata, uuid):
174178
def remove_suite_link(self, uuid):
175179
if self.links.get(uuid):
176180
self.links.pop(uuid)
181+
182+
def close(self):
183+
for plugin in [self.logger, self.listener]:
184+
name = allure_commons.plugin_manager.get_name(plugin)
185+
allure_commons.plugin_manager.unregister(name=name)

allure-robotframework/src/utils.py renamed to allure-robotframework/src/listener/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import absolute_import
22
from allure_commons.model2 import Status, Label, Parameter
33
from allure_commons.types import LabelType
4-
from allure_robotframework.constants import RobotStatus
4+
from allure_robotframework.types import RobotStatus
55

66

77
def get_allure_status(status):

allure-robotframework/test/library/run.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ def robot_run_with_allure(work_dir, *args, **kwargs):
3838
stdout_file = os.path.join(output_dir, 'stdout.txt')
3939

4040
def target(*a, **kw):
41+
42+
# ToDo: fix it (_core not works correctly with multiprocessing)
43+
import six
44+
import allure_commons
45+
if six.PY2:
46+
reload(allure_commons._core)
47+
else:
48+
import importlib
49+
importlib.reload(allure_commons._core)
50+
4151
listener = allure_robotframework(logger_path=allure_dir)
4252

4353
with open(stdout_file, 'w+') as stdout:

0 commit comments

Comments
 (0)