Skip to content

Commit ef1d51a

Browse files
authored
add statistic (#148)
1 parent b40f960 commit ef1d51a

File tree

4 files changed

+23
-16
lines changed

4 files changed

+23
-16
lines changed

allure-behave/src/listener.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from allure_commons.reporter import AllureReporter
66
from allure_commons.utils import uuid4
77
from allure_commons.utils import now
8+
from allure_commons.utils import platform_label
89
from allure_commons.types import LabelType, AttachmentType
910
from allure_commons.model2 import TestResult
1011
from allure_commons.model2 import TestStepResult
@@ -21,6 +22,7 @@
2122
from allure_behave.utils import fixture_status, fixture_status_details
2223
from allure_behave.utils import step_table
2324

25+
2426
BEFORE_FIXTURES = ['before_all', 'before_tag', 'before_feature', 'before_scenario']
2527
AFTER_FIXTURES = ['after_all', 'after_tag', 'after_feature', 'after_scenario']
2628
FIXTURES = BEFORE_FIXTURES + AFTER_FIXTURES
@@ -84,20 +86,15 @@ def start_test(self, parent_uuid, uuid, name, parameters, context):
8486
self.execution_context.append(uuid)
8587

8688
test_case = TestResult(uuid=uuid, start=now())
87-
8889
test_case.name = scenario_name(scenario)
8990
test_case.historyId = scenario_history_id(scenario)
9091
test_case.description = '\n'.join(scenario.description)
91-
92-
labels = []
93-
feature_label = Label(name=LabelType.FEATURE.value, value=scenario.feature.name)
94-
severity = (Label(name=LabelType.SEVERITY.value, value=scenario_severity(scenario).value))
95-
labels.append(feature_label)
96-
labels.append(severity)
97-
labels += [Label(name=LabelType.TAG.value, value=tag) for tag in scenario_tags(scenario)]
98-
9992
test_case.parameters = scenario_parameters(scenario)
100-
test_case.labels = labels
93+
test_case.labels.extend([Label(name=LabelType.TAG, value=tag) for tag in scenario_tags(scenario)])
94+
test_case.labels.append(Label(name=LabelType.SEVERITY, value=scenario_severity(scenario).value))
95+
test_case.labels.append(Label(name=LabelType.FEATURE, value=scenario.feature.name))
96+
test_case.labels.append(Label(name=LabelType.FRAMEWORK, value='behave'))
97+
test_case.labels.append(Label(name=LabelType.LANGUAGE, value=platform_label()))
10198

10299
self.logger.schedule_test(uuid, test_case)
103100

allure-pytest/src/listener.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
import pytest
22
import allure_commons
3-
43
from allure_commons.utils import now
54
from allure_commons.utils import md5
65
from allure_commons.utils import uuid4
76
from allure_commons.utils import represent
8-
7+
from allure_commons.utils import platform_label
98
from allure_commons.reporter import AllureReporter
10-
119
from allure_commons.model2 import TestStepResult, TestResult, TestBeforeResult, TestAfterResult
1210
from allure_commons.model2 import TestResultContainer
1311
from allure_commons.model2 import StatusDetails
1412
from allure_commons.model2 import Parameter
1513
from allure_commons.model2 import Label, Link
1614
from allure_commons.model2 import Status
1715
from allure_commons.types import LabelType
18-
1916
from allure_pytest.utils import allure_labels, allure_links, pytest_markers
2017
from allure_pytest.utils import allure_full_name, allure_package
2118

@@ -72,9 +69,12 @@ def pytest_runtest_protocol(self, item, nextitem):
7269

7370
yield
7471

75-
test_case.labels += [Label(name, value) for name, value in allure_labels(item)]
72+
test_case.labels.extend([Label(name=name, value=value) for name, value in allure_labels(item)])
73+
test_case.labels.extend([Label(name=LabelType.TAG, value=value) for value in pytest_markers(item)])
74+
test_case.labels.append(Label(name=LabelType.FRAMEWORK, value='behave'))
75+
test_case.labels.append(Label(name=LabelType.LANGUAGE, value=platform_label()))
76+
7677
test_case.links += [Link(link_type, url, name) for link_type, url, name in allure_links(item)]
77-
test_case.labels += [Label(LabelType.TAG, value) for value in pytest_markers(item)]
7878

7979
test_case.fullName = allure_full_name(item.nodeid)
8080
test_case.historyId = md5(test_case.fullName)

allure-python-commons/src/types.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ class LabelType(str, Enum):
2525
THREAD = 'thread'
2626
HOST = 'host'
2727
TAG = 'tag'
28+
FRAMEWORK = 'framework'
29+
LANGUAGE = 'language'
2830

2931

3032
class AttachmentType(Enum):

allure-python-commons/src/utils.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import uuid
55
import inspect
66
import hashlib
7+
import platform
78

89
from six import text_type
910

@@ -24,6 +25,13 @@ def now():
2425
return int(round(1000 * time.time()))
2526

2627

28+
def platform_label():
29+
major_version, _, __ = platform.python_version_tuple()
30+
implementation = platform.python_implementation()
31+
return '{implementation}{major_version}'.format(implementation=implementation.lower(),
32+
major_version=major_version)
33+
34+
2735
def represent(item):
2836
"""
2937
>>> represent(None)

0 commit comments

Comments
 (0)