| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 7331fb0 commit 2079164
8 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,7 +17,7 @@ def decorate_as_label(self, label_type, labels): | |||
| 17 | 17 | @allure_commons.hookimpl | |
| 18 | 18 | def decorate_as_link(self, url, link_type, name): | |
| 19 | 19 | allure_link_marker = u'{prefix}.{link_type}'.format(prefix=ALLURE_LINK_PREFIX, link_type=link_type) | |
| 20 | - pattern = dict(self.config.option.allure_link_pattern).get(str(link_type), u'{}') | ||
| 20 | + pattern = dict(self.config.option.allure_link_pattern).get(link_type, u'{}') | ||
| 21 | 21 | url = pattern.format(url) | |
| 22 | 22 | allure_link = getattr(pytest.mark, allure_link_marker) | |
| 23 | 23 | return allure_link(url, name=name) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -68,8 +68,8 @@ def pytest_runtest_protocol(self, item, nextitem): | |||
| 68 | 68 | ||
| 69 | 69 | yield | |
| 70 | 70 | ||
| 71 | - test_case.labels = [Label(name, value) for name, value in allure_labels(item)] | ||
| 72 | - test_case.links = [Link(link_type, url, name) for link_type, url, name in allure_links(item)] | ||
| 71 | + test_case.labels += [Label(name, value) for name, value in allure_labels(item)] | ||
| 72 | + test_case.links += [Link(link_type, url, name) for link_type, url, name in allure_links(item)] | ||
| 73 | 73 | test_case.fullName = allure_full_name(item.nodeid) | |
| 74 | 74 | test_case.historyId = md5(test_case.fullName) | |
| 75 | 75 | test_case.labels.append(Label('package', allure_package(item.nodeid))) | |
@@ -170,6 +170,15 @@ def attach_data(self, body, name, attachment_type, extension): | |||
| 170 | 170 | def attach_file(self, source, name, attachment_type, extension): | |
| 171 | 171 | self.allure_logger.attach_file(uuid4(), source, name=name, attachment_type=attachment_type, extension=extension) | |
| 172 | 172 | ||
| 173 | + @allure_commons.hookimpl | ||
| 174 | + def add_link(self, url, link_type, name): | ||
| 175 | + self.allure_logger.update_test(None, links=[Link(link_type, url, name)]) | ||
| 176 | + | ||
| 177 | + @allure_commons.hookimpl | ||
| 178 | + def add_label(self, label_type, labels): | ||
| 179 | + for label in labels: | ||
| 180 | + self.allure_logger.update_test(None, labels=Label(label_type, label)) | ||
| 181 | + | ||
| 173 | 182 | ||
| 174 | 183 | class ItemCache(object): | |
| 175 | 184 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -51,11 +51,11 @@ def allure_labels(item): | |||
| 51 | 51 | if keyword.startswith(ALLURE_LABEL_PREFIX): | |
| 52 | 52 | marker = item.get_marker(keyword) | |
| 53 | 53 | label_type = marker.kwargs['label_type'] | |
| 54 | - if label_type.value in ALLURE_UNIQUE_LABELS: | ||
| 55 | - yield (label_type.value, marker.args[0]) | ||
| 54 | + if label_type in ALLURE_UNIQUE_LABELS: | ||
| 55 | + yield (label_type, marker.args[0]) | ||
| 56 | 56 | else: | |
| 57 | 57 | for value in marker.args: | |
| 58 | - yield (label_type.value, value) | ||
| 58 | + yield (label_type, value) | ||
| 59 | 59 | ||
| 60 | 60 | ||
| 61 | 61 | def allure_links(item): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,56 @@ | |||
| 1 | + """ | ||
| 2 | + >>> allure_report = getfixture('allure_report') | ||
| 3 | + >>> assert_that(allure_report, | ||
| 4 | + ... all_of( | ||
| 5 | + ... has_property('test_cases', has_length(3)), | ||
| 6 | + ... has_property('test_groups', has_length(0)) | ||
| 7 | + ... )) # doctest: +SKIP | ||
| 8 | + """ | ||
| 9 | + | ||
| 10 | + import allure | ||
| 11 | + | ||
| 12 | + | ||
| 13 | + @allure.label('user_label', 'work', 'cool') | ||
| 14 | + def test_user_label(): | ||
| 15 | + """ | ||
| 16 | + >>> allure_report = getfixture('allure_report') | ||
| 17 | + >>> assert_that(allure_report, | ||
| 18 | + ... has_test_case('test_user_label', | ||
| 19 | + ... all_of( | ||
| 20 | + ... has_label('user_label', 'work'), | ||
| 21 | + ... has_label('user_label', 'cool'), | ||
| 22 | + ... ) | ||
| 23 | + ... )) | ||
| 24 | + """ | ||
| 25 | + pass | ||
| 26 | + | ||
| 27 | + | ||
| 28 | + def test_user_dynamic_label(): | ||
| 29 | + """ | ||
| 30 | + >>> allure_report = getfixture('allure_report') | ||
| 31 | + >>> assert_that(allure_report, | ||
| 32 | + ... has_test_case('test_user_dynamic_label', | ||
| 33 | + ... all_of( | ||
| 34 | + ... has_label('user_label', 'work'), | ||
| 35 | + ... has_label('user_label', 'cool'), | ||
| 36 | + ... ) | ||
| 37 | + ... )) | ||
| 38 | + """ | ||
| 39 | + allure.dynamic.label('user_label', 'work', 'cool') | ||
| 40 | + pass | ||
| 41 | + | ||
| 42 | + | ||
| 43 | + @allure.label('user_label', 'work') | ||
| 44 | + def test_update_labels(): | ||
| 45 | + """ | ||
| 46 | + >>> allure_report = getfixture('allure_report') | ||
| 47 | + >>> assert_that(allure_report, | ||
| 48 | + ... has_test_case('test_user_dynamic_label', | ||
| 49 | + ... all_of( | ||
| 50 | + ... has_label('user_label', 'work'), | ||
| 51 | + ... has_label('user_label', 'cool'), | ||
| 52 | + ... ) | ||
| 53 | + ... )) | ||
| 54 | + """ | ||
| 55 | + allure.dynamic.label('user_label', 'very cool') | ||
| 56 | + pass | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,3 @@ | |||
| 1 | - from functools import partial | ||
| 2 | 1 | from functools import wraps | |
| 3 | 2 | ||
| 4 | 3 | from allure_commons._core import plugin_manager | |
@@ -24,10 +23,6 @@ def severity(severity_level): | |||
| 24 | 23 | return label(LabelType.SEVERITY, severity_level) | |
| 25 | 24 | ||
| 26 | 25 | ||
| 27 | - def tag(*tags): | ||
| 28 | - return label(LabelType.TAG, *tags) | ||
| 29 | - | ||
| 30 | - | ||
| 31 | 26 | def feature(*features): | |
| 32 | 27 | return label(LabelType.FEATURE, *features) | |
| 33 | 28 | ||
@@ -36,6 +31,10 @@ def story(*stories): | |||
| 36 | 31 | return label(LabelType.STORY, *stories) | |
| 37 | 32 | ||
| 38 | 33 | ||
| 34 | + def tag(*tags): | ||
| 35 | + return label(LabelType.TAG, *tags) | ||
| 36 | + | ||
| 37 | + | ||
| 39 | 38 | def link(url, link_type=LinkType.LINK, name=None): | |
| 40 | 39 | return safely(plugin_manager.hook.decorate_as_link(url=url, link_type=link_type, name=name)) | |
| 41 | 40 | ||
@@ -48,24 +47,39 @@ def testcase(url, name=None): | |||
| 48 | 47 | return link(url, link_type=LinkType.TEST_CASE, name=name) | |
| 49 | 48 | ||
| 50 | 49 | ||
| 51 | - def add_label(label_type, labels): | ||
| 52 | - print("Y"*29) | ||
| 50 | + class Dynamic(object): | ||
| 51 | + | ||
| 52 | + @staticmethod | ||
| 53 | + def label(label_type, *labels): | ||
| 54 | + plugin_manager.hook.add_label(label_type=label_type, labels=labels) | ||
| 53 | 55 | ||
| 56 | + @staticmethod | ||
| 57 | + def severity(severity_level): | ||
| 58 | + Dynamic.label(LabelType.SEVERITY, severity_level) | ||
| 54 | 59 | ||
| 55 | - def add_link(url, link_type=LinkType.LINK, name=None): | ||
| 56 | - print ("X"*23) | ||
| 60 | + @staticmethod | ||
| 61 | + def feature(*features): | ||
| 62 | + Dynamic.label(LabelType.FEATURE, *features) | ||
| 57 | 63 | ||
| 64 | + @staticmethod | ||
| 65 | + def story(*stories): | ||
| 66 | + Dynamic.label(LabelType.STORY, *stories) | ||
| 58 | 67 | ||
| 59 | - class Dynamic(object): | ||
| 60 | - label = partial(add_label) | ||
| 61 | - severity = partial(add_label, LabelType.SEVERITY) | ||
| 62 | - tag = partial(add_label, LabelType.TAG) | ||
| 63 | - feature = partial(add_label, LabelType.FEATURE) | ||
| 64 | - story = partial(add_label, LabelType.STORY) | ||
| 65 | - | ||
| 66 | - link = partial(add_link) | ||
| 67 | - issue = partial(add_link, link_type=LinkType.ISSUE) | ||
| 68 | - testcase = partial(add_link, link_type=LinkType.TEST_CASE) | ||
| 68 | + @staticmethod | ||
| 69 | + def tag(*tags): | ||
| 70 | + Dynamic.label(LabelType.TAG, *tags) | ||
| 71 | + | ||
| 72 | + @staticmethod | ||
| 73 | + def link(url, link_type=LinkType.LINK, name=None): | ||
| 74 | + plugin_manager.hook.add_link(url=url, link_type=link_type, name=name) | ||
| 75 | + | ||
| 76 | + @staticmethod | ||
| 77 | + def issue(url, name=None): | ||
| 78 | + Dynamic.link(url, link_type=LinkType.TEST_CASE, name=name) | ||
| 79 | + | ||
| 80 | + @staticmethod | ||
| 81 | + def testcase(url, name=None): | ||
| 82 | + Dynamic.link(url, link_type=LinkType.TEST_CASE, name=name) | ||
| 69 | 83 | ||
| 70 | 84 | ||
| 71 | 85 | def step(title): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,11 +9,21 @@ def decorate_as_label(label_type, labels): | |||
| 9 | 9 | """ label """ | |
| 10 | 10 | ||
| 11 | 11 | ||
| 12 | + @hookspec | ||
| 13 | + def add_label(label_type, labels): | ||
| 14 | + """ label """ | ||
| 15 | + | ||
| 16 | + | ||
| 12 | 17 | @hookspec | |
| 13 | 18 | def decorate_as_link(url, link_type, name): | |
| 14 | 19 | """ url """ | |
| 15 | 20 | ||
| 16 | 21 | ||
| 22 | + @hookspec | ||
| 23 | + def add_link(url, link_type, name): | ||
| 24 | + """ url """ | ||
| 25 | + | ||
| 26 | + | ||
| 17 | 27 | @hookspec | |
| 18 | 28 | def start_step(uuid, title, params): | |
| 19 | 29 | """ step """ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,7 +17,7 @@ def __init__(self, report_dir): | |||
| 17 | 17 | os.makedirs(report_dir) | |
| 18 | 18 | ||
| 19 | 19 | def _update_item(self, uuid, **kwargs): | |
| 20 | - item = self._items[uuid] | ||
| 20 | + item = self._items[uuid] if uuid else self._items[next(reversed(self._items))] | ||
| 21 | 21 | for name, value in kwargs.items(): | |
| 22 | 22 | attr = getattr(item, name) | |
| 23 | 23 | if isinstance(attr, list): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,29 +4,20 @@ | |||
| 4 | 4 | ||
| 5 | 5 | ||
| 6 | 6 | class Severity(str, Enum): | |
| 7 | - def __str__(self): | ||
| 8 | - return self.value | ||
| 9 | - | ||
| 10 | 7 | BLOCKER = 'blocker' | |
| 11 | 8 | CRITICAL = 'critical' | |
| 12 | 9 | NORMAL = 'normal' | |
| 13 | 10 | MINOR = 'minor' | |
| 14 | 11 | TRIVIAL = 'trivial' | |
| 15 | 12 | ||
| 16 | 13 | ||
| 17 | - class LinkType(Enum): | ||
| 18 | - def __str__(self): | ||
| 19 | - return self.value | ||
| 20 | - | ||
| 14 | + class LinkType(object): | ||
| 21 | 15 | LINK = 'link' | |
| 22 | 16 | ISSUE = 'issue' | |
| 23 | 17 | TEST_CASE = 'test_case' | |
| 24 | 18 | ||
| 25 | 19 | ||
| 26 | - class LabelType(Enum): | ||
| 27 | - def __str__(self): | ||
| 28 | - return self.value | ||
| 29 | - | ||
| 20 | + class LabelType(str, Enum): | ||
| 30 | 21 | FEATURE = 'feature' | |
| 31 | 22 | STORY = 'story' | |
| 32 | 23 | SEVERITY = 'severity' | |
| Back | FazBrowse Home | New Git URL |
0 commit comments