Skip to content

Commit 54c0445

Browse files
committed
Custom Item name: done
1 parent ea3e87c commit 54c0445

File tree

6 files changed

+113
-1
lines changed

6 files changed

+113
-1
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Copyright 2024 EPAM Systems
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
import pytest
15+
16+
TEST_NAME_ARGS = 'Test name by mark'
17+
18+
19+
@pytest.mark.name(TEST_NAME_ARGS)
20+
def test_name_by_mark_args():
21+
"""Simple example test with the name comes from Pytest mark."""
22+
assert True
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Copyright 2024 EPAM Systems
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
import pytest
15+
16+
TEST_NAME_EMPTY = 'examples/custom_name/test_custom_name_empty.py::test_name_by_mark_empty'
17+
18+
19+
@pytest.mark.name()
20+
def test_name_by_mark_empty():
21+
"""Simple example test with the name comes from Pytest mark."""
22+
assert True
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Copyright 2024 EPAM Systems
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
import pytest
15+
16+
TEST_NAME_KWARGS = 'Test name by mark, kwargs'
17+
18+
19+
@pytest.mark.name(name=TEST_NAME_KWARGS)
20+
def test_name_by_mark_kwargs():
21+
"""Simple example test with the name comes from Pytest mark."""
22+
assert True

pytest_reportportal/plugin.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ def register_markers(config) -> None:
165165
"params [parameter names as list] - use only specified"
166166
"parameters"
167167
)
168+
config.addinivalue_line(
169+
"markers", "name(name): report the test case with a custom Name."
170+
)
168171

169172

170173
def check_connection(agent_config: AgentConfig):

pytest_reportportal/service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ def _create_suite_path(self, item: Item):
442442
self._lock(leaf, lambda p: self._create_suite(p))
443443

444444
def _get_item_name(self, mark) -> Optional[str]:
445-
pass
445+
return mark.kwargs.get('name', mark.args[0] if mark.args else None)
446446

447447
def _get_code_ref(self, item):
448448
# Generate script path from work dir, use only backslashes to have the
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Copyright 2024 EPAM Systems
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from unittest import mock
16+
17+
import pytest
18+
19+
from custom_name.test_custom_name_args import TEST_NAME_ARGS
20+
from custom_name.test_custom_name_empty import TEST_NAME_EMPTY
21+
from custom_name.test_custom_name_kwargs import TEST_NAME_KWARGS
22+
from tests import REPORT_PORTAL_SERVICE
23+
from tests.helpers import utils
24+
25+
26+
@pytest.mark.parametrize('test, expected', [
27+
('examples/custom_name/test_custom_name_args.py', TEST_NAME_ARGS),
28+
('examples/custom_name/test_custom_name_kwargs.py', TEST_NAME_KWARGS),
29+
('examples/custom_name/test_custom_name_empty.py', TEST_NAME_EMPTY)
30+
])
31+
@mock.patch(REPORT_PORTAL_SERVICE)
32+
def test_custom_attribute_report(mock_client_init, test, expected):
33+
result = utils.run_pytest_tests(tests=[test], variables=utils.DEFAULT_VARIABLES)
34+
assert int(result) == 0, 'Exit code should be 0 (no errors)'
35+
36+
mock_client = mock_client_init.return_value
37+
start_count = mock_client.start_test_item.call_count
38+
finish_count = mock_client.finish_test_item.call_count
39+
assert start_count == finish_count == 1, 'Incorrect number of "start_test_item" or "finish_test_item" calls'
40+
41+
call_args = mock_client.start_test_item.call_args_list
42+
step_call_args = call_args[0][1]
43+
assert step_call_args['name'] == expected, 'Incorrect item name'

0 commit comments

Comments
 (0)