Skip to content

Commit

Permalink
Custom Item name: done
Browse files Browse the repository at this point in the history
  • Loading branch information
HardNorth committed Dec 3, 2024
1 parent ea3e87c commit 54c0445
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 1 deletion.
22 changes: 22 additions & 0 deletions examples/custom_name/test_custom_name_args.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2024 EPAM Systems
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import pytest

TEST_NAME_ARGS = 'Test name by mark'


@pytest.mark.name(TEST_NAME_ARGS)
def test_name_by_mark_args():
"""Simple example test with the name comes from Pytest mark."""
assert True
22 changes: 22 additions & 0 deletions examples/custom_name/test_custom_name_empty.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2024 EPAM Systems
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import pytest

TEST_NAME_EMPTY = 'examples/custom_name/test_custom_name_empty.py::test_name_by_mark_empty'


@pytest.mark.name()
def test_name_by_mark_empty():
"""Simple example test with the name comes from Pytest mark."""
assert True
22 changes: 22 additions & 0 deletions examples/custom_name/test_custom_name_kwargs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2024 EPAM Systems
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import pytest

TEST_NAME_KWARGS = 'Test name by mark, kwargs'


@pytest.mark.name(name=TEST_NAME_KWARGS)
def test_name_by_mark_kwargs():
"""Simple example test with the name comes from Pytest mark."""
assert True
3 changes: 3 additions & 0 deletions pytest_reportportal/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ def register_markers(config) -> None:
"params [parameter names as list] - use only specified"
"parameters"
)
config.addinivalue_line(
"markers", "name(name): report the test case with a custom Name."
)


def check_connection(agent_config: AgentConfig):
Expand Down
2 changes: 1 addition & 1 deletion pytest_reportportal/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ def _create_suite_path(self, item: Item):
self._lock(leaf, lambda p: self._create_suite(p))

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

def _get_code_ref(self, item):
# Generate script path from work dir, use only backslashes to have the
Expand Down
43 changes: 43 additions & 0 deletions tests/integration/test_custom_name.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Copyright 2024 EPAM Systems
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from unittest import mock

import pytest

from custom_name.test_custom_name_args import TEST_NAME_ARGS
from custom_name.test_custom_name_empty import TEST_NAME_EMPTY
from custom_name.test_custom_name_kwargs import TEST_NAME_KWARGS
from tests import REPORT_PORTAL_SERVICE
from tests.helpers import utils


@pytest.mark.parametrize('test, expected', [
('examples/custom_name/test_custom_name_args.py', TEST_NAME_ARGS),
('examples/custom_name/test_custom_name_kwargs.py', TEST_NAME_KWARGS),
('examples/custom_name/test_custom_name_empty.py', TEST_NAME_EMPTY)
])
@mock.patch(REPORT_PORTAL_SERVICE)
def test_custom_attribute_report(mock_client_init, test, expected):
result = utils.run_pytest_tests(tests=[test], variables=utils.DEFAULT_VARIABLES)
assert int(result) == 0, 'Exit code should be 0 (no errors)'

mock_client = mock_client_init.return_value
start_count = mock_client.start_test_item.call_count
finish_count = mock_client.finish_test_item.call_count
assert start_count == finish_count == 1, 'Incorrect number of "start_test_item" or "finish_test_item" calls'

call_args = mock_client.start_test_item.call_args_list
step_call_args = call_args[0][1]
assert step_call_args['name'] == expected, 'Incorrect item name'

0 comments on commit 54c0445

Please sign in to comment.