Skip to content

Commit 31a5157

Browse files
committed
test: tighten globals tests a little
1 parent fa79888 commit 31a5157

5 files changed

Lines changed: 59 additions & 14 deletions

File tree

allure-python-commons-test/src/result.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,8 @@ def with_message_contains(string):
251251
def with_trace_contains(string):
252252
return has_entry("trace", contains_string(string))
253253

254+
def with_no_trace():
255+
return not_(has_entry("trace", anything()))
254256

255257
def with_excluded():
256258
return has_entry("excluded", True)

tests/allure_behave/acceptance/behave_support/hooks/hook_test.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import allure
22
from tests.allure_behave.behave_runner import AllureBehaveRunner as Runner
3-
from hamcrest import assert_that, all_of, not_, equal_to, has_item
3+
from hamcrest import assert_that, all_of, not_, equal_to, has_item, has_length
44
from allure_commons_test.container import has_container, has_before, has_after
55
from allure_commons_test.report import has_test_case
66
from allure_commons_test.result import with_status
@@ -137,6 +137,11 @@ def after_all(context):
137137
"""
138138
)
139139

140+
assert_that(
141+
behave_runner.allure_results.globals,
142+
has_length(2),
143+
)
144+
140145
assert_that(
141146
behave_runner.allure_results.globals,
142147
has_item(

tests/allure_pytest/acceptance/attachment/attachment_hook_test.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
from hamcrest import assert_that, has_item, all_of, has_entry, equal_to, ends_with, not_, anything
1+
from hamcrest import assert_that, has_item, all_of
2+
from hamcrest import has_entry, equal_to, ends_with
3+
from hamcrest import not_, anything, has_length
24
from tests.allure_pytest.pytest_runner import AllurePytestRunner
35

46
from allure_commons_test.report import has_test_case
@@ -7,6 +9,7 @@
79
from allure_commons_test.result import has_global_error
810
from allure_commons_test.result import with_message_contains
911
from allure_commons_test.result import with_trace_contains
12+
from allure_commons_test.result import with_no_trace
1013

1114

1215
def test_attach_from_runtest_teardown(allure_pytest_runner: AllurePytestRunner):
@@ -88,6 +91,11 @@ def pytest_sessionfinish(session, exitstatus):
8891
)
8992
)
9093

94+
assert_that(
95+
allure_results.globals,
96+
has_length(5),
97+
)
98+
9199
assert_that(
92100
allure_results.globals,
93101
all_of(
@@ -106,14 +114,9 @@ def pytest_sessionfinish(session, exitstatus):
106114
)
107115
),
108116
has_item(
109-
has_entry(
110-
"errors",
111-
has_item(
112-
all_of(
113-
with_message_contains("message only error"),
114-
not_(has_entry("trace", anything()))
115-
)
116-
)
117+
has_global_error(
118+
with_message_contains("message only error"),
119+
with_no_trace(),
117120
)
118121
),
119122
has_item(

tests/allure_pytest_bdd/acceptance/attachments_test.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from hamcrest import ends_with
66
from hamcrest import has_item
77
from hamcrest import not_
8+
from hamcrest import has_length
89

910
from allure_commons_test.content import csv_equivalent
1011
from allure_commons_test.report import has_test_case
@@ -282,6 +283,8 @@ def pytest_sessionfinish(session, exitstatus):
282283
conftest_literal=conftest_content,
283284
)
284285

286+
assert_that(allure_results.globals, has_length(2))
287+
285288
assert_that(
286289
allure_results.globals,
287290
has_item(

tests/allure_robotframework/acceptance/allure_api/attachment/attachment_test.py

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
""" ./allure-robotframework/examples/attachment.rst """
22

33
from pytest import MonkeyPatch
4-
from hamcrest import assert_that, equal_to, has_item
4+
from hamcrest import assert_that, equal_to, has_item, has_length
55
from tests.allure_robotframework.robot_runner import AllureRobotRunner
66
from allure_commons_test.report import has_test_case
77
from allure_commons_test.result import has_attachment_with_content
@@ -156,17 +156,31 @@ def test_global_attachment_and_error(robot_runner: AllureRobotRunner):
156156
"""
157157
*** Settings ***
158158
Library AllureLibrary
159+
Library ./lib.py
159160
Suite Setup Global Attach robot global attachment name=robot global
160161
Suite Teardown Global Error robot global error
161162
162163
*** Test Cases ***
163164
Global Attachment
164-
No Operation
165+
Add Globals From Code
165166
"""
166-
)
167-
}
167+
),
168+
},
169+
library_literals={
170+
"lib.py": (
171+
"""
172+
import allure
173+
174+
def add_globals_from_code():
175+
allure.global_attach(body="global body", name="global attachment")
176+
allure.global_error("message only error")
177+
"""
178+
),
179+
},
168180
)
169181

182+
assert_that(robot_runner.allure_results.globals, has_length(4))
183+
170184
assert_that(
171185
robot_runner.allure_results.globals,
172186
has_item(
@@ -177,6 +191,16 @@ def test_global_attachment_and_error(robot_runner: AllureRobotRunner):
177191
)
178192
)
179193
)
194+
assert_that(
195+
robot_runner.allure_results.globals,
196+
has_item(
197+
has_global_attachment_with_content(
198+
robot_runner.allure_results.attachments,
199+
equal_to("global body"),
200+
name="global attachment"
201+
)
202+
)
203+
)
180204
assert_that(
181205
robot_runner.allure_results.globals,
182206
has_item(
@@ -185,3 +209,11 @@ def test_global_attachment_and_error(robot_runner: AllureRobotRunner):
185209
)
186210
)
187211
)
212+
assert_that(
213+
robot_runner.allure_results.globals,
214+
has_item(
215+
has_global_error(
216+
with_message_contains("message only error")
217+
)
218+
)
219+
)

0 commit comments

Comments
 (0)