1+ # Copyright (c) 2023 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+ """This module includes integration tests for Test Case ID report with use_index parameter."""
15+
16+ from unittest import mock
17+
18+ import pytest
19+
20+ from examples .test_case_id import (
21+ test_case_id_decorator_use_index_false ,
22+ test_case_id_decorator_use_index_partial_params ,
23+ test_case_id_decorator_use_index_true ,
24+ )
25+ from tests import REPORT_PORTAL_SERVICE
26+ from tests .helpers import utils
27+
28+
29+ @mock .patch (REPORT_PORTAL_SERVICE )
30+ @pytest .mark .parametrize (
31+ ["test" , "expected_id" ],
32+ [
33+ # Test use_index=True: should use parameter indices instead of values
34+ # Format should be: ('param1', 0),('param2', 0) instead of value1,value2
35+ (
36+ "examples/test_case_id/test_case_id_decorator_use_index_true.py" ,
37+ test_case_id_decorator_use_index_true .TEST_CASE_ID + "[('param1', 0),('param2', 0)]" ,
38+ ),
39+ # Test use_index=False: should use parameter values (default behavior)
40+ (
41+ "examples/test_case_id/test_case_id_decorator_use_index_false.py" ,
42+ test_case_id_decorator_use_index_false .TEST_CASE_ID + "[value1,value2]" ,
43+ ),
44+ # Test use_index=True with selected params: should use index for selected param only
45+ # Should be ('param1', 0) instead of value1
46+ (
47+ "examples/test_case_id/test_case_id_decorator_use_index_partial_params.py" ,
48+ test_case_id_decorator_use_index_partial_params .TEST_CASE_ID + "[('param1', 0)]" ,
49+ ),
50+ ],
51+ )
52+ def test_use_index_parameters (mock_client_init , test , expected_id ):
53+ """Verify the use_index parameter in Test Case ID functionality.
54+
55+ This test verifies that the new use_index parameter works correctly for parameterized tests.
56+ When use_index=True, the test case ID should include parameter indices instead of parameter values.
57+ This is useful for scenarios where parameter values might change between test runs but the indices
58+ remain constant, ensuring that retry groups are properly maintained.
59+
60+ The test covers:
61+ 1. use_index=True with all parameters - should use (param_name, index) format
62+ 2. use_index=False - should use parameter values (default behavior)
63+ 3. use_index=True with selected parameters - should use indices only for selected params
64+
65+ :param mock_client_init: Pytest fixture for mocking the ReportPortal client
66+ :param test: a test file path to run
67+ :param expected_id: the expected Test Case ID format
68+ """
69+ result = utils .run_pytest_tests (tests = [test ])
70+ assert int (result ) == 0 , "Exit code should be 0 (no errors)"
71+
72+ mock_client = mock_client_init .return_value
73+ assert mock_client .start_test_item .call_count > 0 , '"start_test_item" called incorrect number of times'
74+
75+ call_args = mock_client .start_test_item .call_args_list
76+ step_call_args = call_args [- 1 ][1 ]
77+ assert step_call_args ["test_case_id" ] == expected_id
0 commit comments