Repository navigation
Expand file tree
/
Copy pathstep_attribute_placeholder_test.py
More file actions
98 lines (73 loc) · 2.33 KB
/
Copy pathstep_attribute_placeholder_test.py
File metadata and controls
98 lines (73 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
"""
Regression tests for object attribute access in step title placeholders.
See https://github.com/allure-framework/allure-python/issues/896.
"""
from hamcrest import assert_that
from tests.allure_pytest.pytest_runner import AllurePytestRunner
from allure_commons_test.report import has_test_case
from allure_commons_test.result import has_step
def test_step_with_dataclass_attribute_placeholder(allure_pytest_runner: AllurePytestRunner):
"""
>>> import allure
>>> from dataclasses import dataclass
>>> @dataclass
... class Item:
... name: str
>>> @allure.step("Process item: {item.name}")
... def process(item):
... pass
>>> def test_dataclass_attribute_access():
... process(Item(name="Widget"))
"""
allure_results = allure_pytest_runner.run_docstring()
assert_that(
allure_results,
has_test_case(
"test_dataclass_attribute_access",
has_step("Process item: 'Widget'"),
),
)
def test_step_with_object_attribute_placeholder(allure_pytest_runner: AllurePytestRunner):
"""
>>> import allure
>>> class Order:
... def __init__(self, status):
... self.status = status
>>> @allure.step("Order is {order.status}")
... def check(order):
... pass
>>> def test_object_attribute_access():
... check(Order("delivered"))
"""
allure_results = allure_pytest_runner.run_docstring()
assert_that(
allure_results,
has_test_case(
"test_object_attribute_access",
has_step("Order is 'delivered'"),
),
)
def test_step_with_nested_attribute_placeholder(allure_pytest_runner: AllurePytestRunner):
"""
>>> import allure
>>> from dataclasses import dataclass
>>> @dataclass
... class Address:
... city: str
>>> @dataclass
... class User:
... address: Address
>>> @allure.step("User from {user.address.city}")
... def greet(user):
... pass
>>> def test_nested_attribute_access():
... greet(User(address=Address(city="Brighton")))
"""
allure_results = allure_pytest_runner.run_docstring()
assert_that(
allure_results,
has_test_case(
"test_nested_attribute_access",
has_step("User from 'Brighton'"),
),
)