Skip to content

Commit f1310e2

Browse files
committed
Add too long BDD Step name truncation on reporting
1 parent eb242c0 commit f1310e2

File tree

5 files changed

+67
-1
lines changed

5 files changed

+67
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Changelog
22

33
## [Unreleased]
4+
### Added
5+
- Too long BDD Step name truncation on reporting, by @HardNorth
46

57
## [5.5.0]
68
### Added
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Feature: Test long step scenario
2+
3+
Scenario: The scenario
4+
Given A very long step. Seriously, this step is ridiculously long. Our users require such a long step and here it is. This is not even a half of the step, it will last really long. I believe you will get tired before you reach the end of the step. Why? Because our users send here a megabyte-length JSONs or things like that, despite our words that this is not good for user experience, since it's hard to read such a long lines on UI and for backend performance, since we use this field in full-text search. OK I'm out of thought what else I can write here, but the step must go on. Probably you will see some random typing soon to get the step longer than it's right now. Because only now we crossed a half of the length we need. Alright, here we go: 39248cht42 3x,r093mhxr0,3hr c089r3423 xk309,,r3 k302uk032 3249xul398u3 at 34r9k39489 aumvi xkr293jed0 i 93u9f32u smhf 09ktc903 a tu09r328 ef5u0fu3v 0k8utf2 u59du9v u423kuc 9f5kv 39kd3uf39 -3940u5kfu5 b3-90485l-k3f. Are you tired? I'm too, but we still need a few words at the end.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Copyright 2025 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+
import logging
16+
17+
from pytest_bdd import given, scenarios
18+
19+
# Import the scenario from the feature file
20+
scenarios("../features/long_step_scenario.feature")
21+
22+
23+
LOGGER = logging.getLogger(__name__)
24+
25+
26+
@given(
27+
"A very long step. Seriously, this step is ridiculously long. Our users require such a long step and here it is. This is not even a half of the step, it will last really long. I believe you will get tired before you reach the end of the step. Why? Because our users send here a megabyte-length JSONs or things like that, despite our words that this is not good for user experience, since it's hard to read such a long lines on UI and for backend performance, since we use this field in full-text search. OK I'm out of thought what else I can write here, but the step must go on. Probably you will see some random typing soon to get the step longer than it's right now. Because only now we crossed a half of the length we need. Alright, here we go: 39248cht42 3x,r093mhxr0,3hr c089r3423 xk309,,r3 k302uk032 3249xul398u3 at 34r9k39489 aumvi xkr293jed0 i 93u9f32u smhf 09ktc903 a tu09r328 ef5u0fu3v 0k8utf2 u59du9v u423kuc 9f5kv 39kd3uf39 -3940u5kfu5 b3-90485l-k3f. Are you tired? I'm too, but we still need a few words at the end." # noqa: E501
28+
)
29+
def step_with_long_text():
30+
LOGGER.info("Step with extremely long text executed successfully")

pytest_reportportal/service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1279,7 +1279,7 @@ def start_bdd_step(self, feature: Feature, scenario: Scenario, step: Step) -> No
12791279
if feature.background:
12801280
background_leaf = scenario_leaf["children"][feature.background]
12811281
self._finish_bdd_step(background_leaf, "PASSED")
1282-
item_id = reporter.start_nested_step(f"{step.keyword} {step.name}", timestamp())
1282+
item_id = reporter.start_nested_step(self._truncate_item_name(f"{step.keyword} {step.name}"), timestamp())
12831283
step_leaf["item_id"] = item_id
12841284
step_leaf["exec"] = ExecStatus.IN_PROGRESS
12851285

tests/integration/test_bdd.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,3 +1130,33 @@ def test_rp_tests_attributes_bdd_tags(mock_client_init):
11301130
assert {"key": "test_key", "value": "test_value"} in attributes
11311131
assert {"value": "ok"} in attributes
11321132
assert {"key": "key", "value": "value"} in attributes
1133+
1134+
1135+
@mock.patch(REPORT_PORTAL_SERVICE)
1136+
def test_long_step(mock_client_init):
1137+
mock_client = setup_mock_for_logging(mock_client_init)
1138+
result = utils.run_pytest_tests(tests=["examples/bdd/step_defs/long_step_scenario_steps.py"])
1139+
assert int(result) == 0, "Exit code should be 0 (no errors)"
1140+
1141+
# Verify scenario is correctly identified
1142+
scenario_call = mock_client.start_test_item.call_args_list[0]
1143+
assert scenario_call[1]["name"] == "Feature: Test long step scenario - Scenario: The scenario"
1144+
assert scenario_call[1]["item_type"] == "STEP"
1145+
assert scenario_call[1]["code_ref"] == "features/long_step_scenario.feature/[SCENARIO:The scenario]"
1146+
1147+
# Verify step is truncated but still identifiable
1148+
step_call = mock_client.start_test_item.call_args_list[1]
1149+
step_name = step_call[0][0]
1150+
assert step_name.startswith("Given A very long step.")
1151+
assert len(step_name) <= 1024, "Step name should be truncated to at most 1024 characters"
1152+
assert step_name.endswith("..."), "Truncated step should have ellipsis"
1153+
1154+
# Verify step details
1155+
assert step_call[0][2] == "step"
1156+
assert step_call[1]["parent_item_id"] == scenario_call[1]["name"] + "_1"
1157+
assert step_call[1]["has_stats"] is False
1158+
1159+
# Verify all steps pass
1160+
finish_calls = mock_client.finish_test_item.call_args_list
1161+
for call in finish_calls:
1162+
assert call[1]["status"] == "PASSED"

0 commit comments

Comments
 (0)