Skip to content

Commit 3c9f60a

Browse files
committed
test: factor out globals tests
1 parent 31a5157 commit 3c9f60a

11 files changed

Lines changed: 289 additions & 271 deletions

File tree

tests/allure_behave/acceptance/allure_api/globals/__init__.py

Whitespace-only changes.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import textwrap
2+
from tests.allure_behave.behave_runner import AllureBehaveRunner as Runner
3+
from hamcrest import assert_that, equal_to, has_item, has_length
4+
from allure_commons_test.result import has_global_attachment_with_content
5+
from allure_commons_test.result import has_global_error
6+
from allure_commons_test.result import with_message_contains
7+
8+
9+
def test_global_attachment_and_error_hooks(behave_runner: Runner):
10+
behave_runner.run_behave(
11+
feature_literals=[
12+
"""
13+
Feature: Global attachments and errors
14+
Scenario: Global hooks
15+
Given noop
16+
"""
17+
],
18+
step_literals=["given('noop')(lambda c: None)"],
19+
environment_literal=textwrap.dedent(
20+
"""
21+
import allure
22+
23+
24+
def before_all(context):
25+
allure.global_attach("behave global attachment", name="behave global")
26+
27+
28+
def after_all(context):
29+
allure.global_error("behave global error")
30+
"""
31+
),
32+
)
33+
34+
assert_that(
35+
behave_runner.allure_results.globals,
36+
has_length(2),
37+
)
38+
39+
assert_that(
40+
behave_runner.allure_results.globals,
41+
has_item(
42+
has_global_attachment_with_content(
43+
behave_runner.allure_results.attachments,
44+
equal_to("behave global attachment"),
45+
name="behave global"
46+
)
47+
)
48+
)
49+
assert_that(
50+
behave_runner.allure_results.globals,
51+
has_item(
52+
has_global_error(
53+
with_message_contains("behave global error")
54+
)
55+
)
56+
)

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

Lines changed: 1 addition & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
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, has_length
3+
from hamcrest import assert_that, all_of, not_, equal_to
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
77
from allure_commons_test.result import has_attachment_with_content
8-
from allure_commons_test.result import has_global_attachment_with_content
9-
from allure_commons_test.result import has_global_error
108
from allure_commons_test.result import has_step
11-
from allure_commons_test.result import with_message_contains
129

1310

1411
def test_global_hooks(behave_runner: Runner):
@@ -114,54 +111,6 @@ def test_tag_hooks(behave_runner: Runner):
114111
)
115112

116113

117-
def test_global_attachment_and_error_hooks(behave_runner: Runner):
118-
behave_runner.run_behave(
119-
feature_literals=[
120-
"""
121-
Feature: Global attachments and errors
122-
Scenario: Global hooks
123-
Given noop
124-
"""
125-
],
126-
step_literals=["given('noop')(lambda c: None)"],
127-
environment_literal="""
128-
import allure
129-
130-
131-
def before_all(context):
132-
allure.global_attach("behave global attachment", name="behave global")
133-
134-
135-
def after_all(context):
136-
allure.global_error("behave global error")
137-
"""
138-
)
139-
140-
assert_that(
141-
behave_runner.allure_results.globals,
142-
has_length(2),
143-
)
144-
145-
assert_that(
146-
behave_runner.allure_results.globals,
147-
has_item(
148-
has_global_attachment_with_content(
149-
behave_runner.allure_results.attachments,
150-
equal_to("behave global attachment"),
151-
name="behave global"
152-
)
153-
)
154-
)
155-
assert_that(
156-
behave_runner.allure_results.globals,
157-
has_item(
158-
has_global_error(
159-
with_message_contains("behave global error")
160-
)
161-
)
162-
)
163-
164-
165114
def test_attachment_before_feature(behave_runner: Runner):
166115
behave_runner.run_behave(
167116
feature_paths=["./test-data/attachment-hook.feature"],
Lines changed: 1 addition & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
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
1+
from hamcrest import assert_that
42
from tests.allure_pytest.pytest_runner import AllurePytestRunner
53

64
from allure_commons_test.report import has_test_case
75
from allure_commons_test.result import has_attachment
8-
from allure_commons_test.result import has_global_attachment_with_content
9-
from allure_commons_test.result import has_global_error
10-
from allure_commons_test.result import with_message_contains
11-
from allure_commons_test.result import with_trace_contains
12-
from allure_commons_test.result import with_no_trace
136

147

158
def test_attach_from_runtest_teardown(allure_pytest_runner: AllurePytestRunner):
@@ -62,74 +55,3 @@ def pytest_runtest_logfinish(*args, **kwargs):
6255
has_attachment(name="attachment from logfinish")
6356
)
6457
)
65-
66-
67-
def test_globals_from_session_hooks(allure_pytest_runner: AllurePytestRunner):
68-
allure_results = allure_pytest_runner.run_pytest(
69-
"""
70-
def test_globals_from_session_hooks():
71-
pass
72-
""",
73-
conftest_literal=(
74-
"""
75-
import allure
76-
77-
78-
def pytest_sessionstart(session):
79-
allure.global_attach(body="global body", name="global attachment")
80-
allure.global_attach.file(__file__, name="global attachment file")
81-
allure.global_error("message only error")
82-
83-
84-
def pytest_sessionfinish(session, exitstatus):
85-
try:
86-
raise ValueError("error from exception")
87-
except ValueError as error:
88-
allure.global_error(error)
89-
allure.global_error("message with trace", "explicit trace")
90-
"""
91-
)
92-
)
93-
94-
assert_that(
95-
allure_results.globals,
96-
has_length(5),
97-
)
98-
99-
assert_that(
100-
allure_results.globals,
101-
all_of(
102-
has_item(
103-
has_global_attachment_with_content(
104-
allure_results.attachments,
105-
equal_to("global body"),
106-
name="global attachment"
107-
)
108-
),
109-
has_item(
110-
has_global_attachment_with_content(
111-
allure_results.attachments,
112-
ends_with("conftest.py"),
113-
name="global attachment file"
114-
)
115-
),
116-
has_item(
117-
has_global_error(
118-
with_message_contains("message only error"),
119-
with_no_trace(),
120-
)
121-
),
122-
has_item(
123-
has_global_error(
124-
with_message_contains("ValueError: error from exception"),
125-
with_trace_contains("raise ValueError")
126-
)
127-
),
128-
has_item(
129-
has_global_error(
130-
with_message_contains("message with trace"),
131-
with_trace_contains("explicit trace")
132-
)
133-
)
134-
)
135-
)

tests/allure_pytest/acceptance/globals/__init__.py

Whitespace-only changes.
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
from hamcrest import assert_that, has_item, all_of
2+
from hamcrest import equal_to, ends_with, has_length
3+
from tests.allure_pytest.pytest_runner import AllurePytestRunner
4+
5+
from allure_commons_test.result import has_global_attachment_with_content
6+
from allure_commons_test.result import has_global_error
7+
from allure_commons_test.result import with_message_contains
8+
from allure_commons_test.result import with_trace_contains
9+
from allure_commons_test.result import with_no_trace
10+
11+
12+
def test_globals_from_session_hooks(allure_pytest_runner: AllurePytestRunner):
13+
allure_results = allure_pytest_runner.run_pytest(
14+
"""
15+
def test_globals_from_session_hooks():
16+
pass
17+
""",
18+
conftest_literal=(
19+
"""
20+
import allure
21+
22+
23+
def pytest_sessionstart(session):
24+
allure.global_attach(body="global body", name="global attachment")
25+
allure.global_attach.file(__file__, name="global attachment file")
26+
allure.global_error("message only error")
27+
28+
29+
def pytest_sessionfinish(session, exitstatus):
30+
try:
31+
raise ValueError("error from exception")
32+
except ValueError as error:
33+
allure.global_error(error)
34+
allure.global_error("message with trace", "explicit trace")
35+
"""
36+
)
37+
)
38+
39+
assert_that(
40+
allure_results.globals,
41+
has_length(5),
42+
)
43+
44+
assert_that(
45+
allure_results.globals,
46+
all_of(
47+
has_item(
48+
has_global_attachment_with_content(
49+
allure_results.attachments,
50+
equal_to("global body"),
51+
name="global attachment"
52+
)
53+
),
54+
has_item(
55+
has_global_attachment_with_content(
56+
allure_results.attachments,
57+
ends_with("conftest.py"),
58+
name="global attachment file"
59+
)
60+
),
61+
has_item(
62+
has_global_error(
63+
with_message_contains("message only error"),
64+
with_no_trace(),
65+
)
66+
),
67+
has_item(
68+
has_global_error(
69+
with_message_contains("ValueError: error from exception"),
70+
with_trace_contains("raise ValueError")
71+
)
72+
),
73+
has_item(
74+
has_global_error(
75+
with_message_contains("message with trace"),
76+
with_trace_contains("explicit trace")
77+
)
78+
)
79+
)
80+
)

tests/allure_pytest_bdd/acceptance/attachments_test.py

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,15 @@
33
from hamcrest import assert_that
44
from hamcrest import equal_to
55
from hamcrest import ends_with
6-
from hamcrest import has_item
76
from hamcrest import not_
8-
from hamcrest import has_length
97

108
from allure_commons_test.content import csv_equivalent
119
from allure_commons_test.report import has_test_case
1210
from allure_commons_test.result import has_attachment
1311
from allure_commons_test.result import has_attachment_with_content
14-
from allure_commons_test.result import has_global_attachment_with_content
15-
from allure_commons_test.result import has_global_error
1612
from allure_commons_test.result import has_step
1713
from allure_commons_test.result import has_parameter
1814
from allure_commons_test.result import doesnt_have_parameter
19-
from allure_commons_test.result import with_message_contains
2015

2116
from tests.allure_pytest.pytest_runner import AllurePytestRunner
2217
from tests.e2e import version_lt
@@ -244,67 +239,6 @@ def pytest_runtest_teardown(item):
244239
)
245240

246241

247-
def test_global_attachment_and_error_from_hook(allure_pytest_bdd_runner: AllurePytestRunner):
248-
feature_content = (
249-
"""
250-
Feature: Foo
251-
Scenario: Bar
252-
Given noop
253-
"""
254-
)
255-
steps_content = (
256-
"""
257-
from pytest_bdd import scenario, given
258-
259-
@scenario("sample.feature", "Bar")
260-
def test_scenario():
261-
pass
262-
263-
@given("noop")
264-
def given_noop():
265-
pass
266-
"""
267-
)
268-
conftest_content = (
269-
"""
270-
import allure
271-
272-
def pytest_sessionstart(session):
273-
allure.global_attach("bdd global attachment", name="bdd global")
274-
275-
def pytest_sessionfinish(session, exitstatus):
276-
allure.global_error("bdd global error")
277-
"""
278-
)
279-
280-
allure_results = allure_pytest_bdd_runner.run_pytest(
281-
("sample.feature", feature_content),
282-
steps_content,
283-
conftest_literal=conftest_content,
284-
)
285-
286-
assert_that(allure_results.globals, has_length(2))
287-
288-
assert_that(
289-
allure_results.globals,
290-
has_item(
291-
has_global_attachment_with_content(
292-
allure_results.attachments,
293-
equal_to("bdd global attachment"),
294-
name="bdd global",
295-
)
296-
)
297-
)
298-
assert_that(
299-
allure_results.globals,
300-
has_item(
301-
has_global_error(
302-
with_message_contains("bdd global error")
303-
)
304-
)
305-
)
306-
307-
308242
@pytest.mark.skipif(version_lt("pytest-bdd", 8), reason="Data tables support added in 8.0.0")
309243
def test_attach_datatable(allure_pytest_bdd_runner: AllurePytestRunner):
310244
feature_content = (

0 commit comments

Comments
 (0)