11""" ./allure-robotframework/examples/attachment.rst """
22
33from 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
55from tests .allure_robotframework .robot_runner import AllureRobotRunner
66from allure_commons_test .report import has_test_case
77from 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