Skip to content

Commit 8c9c10c

Browse files
committed
Add runtime attribute adding test
1 parent a67737f commit 8c9c10c

File tree

3 files changed

+65
-1
lines changed

3 files changed

+65
-1
lines changed

examples/attributes/test_one_attribute.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
@pytest.mark.scope("smoke")
1818
def test_custom_attributes_report():
1919
"""
20-
This is a test with one custom markers which shall appear on
20+
This is a test with one custom marker which shall appear on
2121
ReportPortal on test's item
2222
"""
2323
assert True
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Copyright (c) 2022 https://reportportal.io .
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
#
6+
# https://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License
13+
14+
import pytest
15+
16+
17+
@pytest.mark.scope("smoke")
18+
def test_custom_attributes_report(request):
19+
"""
20+
This is a test with one custom marker as a decorator and one custom marker
21+
added at runtime which shall both appear on ReportPortal on test's item
22+
"""
23+
request.node.add_marker(
24+
pytest.mark.runtime()
25+
)
26+
assert True

tests/integration/test_attributes.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,41 @@ def test_skip_attribute(mock_client_init):
120120
assert utils.attributes_to_tuples(actual_attributes) == {
121121
(None, 'skip')
122122
}
123+
124+
125+
@mock.patch(REPORT_PORTAL_SERVICE)
126+
def test_custom_runtime_attribute_report(mock_client_init):
127+
"""Verify custom attribute is reported.
128+
129+
:param mock_client_init: Pytest fixture
130+
"""
131+
variables = {
132+
'markers': 'scope: to which test scope a test relates\n'
133+
'runtime: runtime attribute mark'
134+
}
135+
variables.update(utils.DEFAULT_VARIABLES.items())
136+
result = utils.run_pytest_tests(
137+
tests=['examples/attributes/test_runtime_attribute.py'],
138+
variables=variables
139+
)
140+
assert int(result) == 0, 'Exit code should be 0 (no errors)'
141+
142+
mock_client = mock_client_init.return_value
143+
assert mock_client.start_test_item.call_count > 0, \
144+
'"start_test_item" called incorrect number of times'
145+
assert mock_client.finish_test_item.call_count > 0, \
146+
'"finish_test_item" called incorrect number of times'
147+
148+
start_call_args = mock_client.start_test_item.call_args_list
149+
start_step_call_args = start_call_args[-1][1]
150+
assert start_step_call_args['attributes'] == [
151+
{'key': 'scope', 'value': 'smoke'}
152+
]
153+
154+
finish_call_args = mock_client.finish_test_item.call_args_list
155+
finish_step_call_args = finish_call_args[-1][1]
156+
actual_attributes = finish_step_call_args['attributes']
157+
attribute_tuple_list = [(kv.get('key'), kv['value'])
158+
for kv in actual_attributes]
159+
160+
assert set(attribute_tuple_list) == {('scope', 'smoke'), (None, 'runtime')}

0 commit comments

Comments
 (0)