Skip to content

Commit fb7c883

Browse files
committed
Add test cases
1 parent e8d46f8 commit fb7c883

File tree

4 files changed

+149
-0
lines changed

4 files changed

+149
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""A simple example test with Test Case ID decorator using parameter values."""
2+
3+
# Copyright (c) 2023 https://reportportal.io .
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# https://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License
15+
16+
import pytest
17+
18+
TEST_CASE_ID = "ISSUE-USE-INDEX-FALSE"
19+
20+
21+
@pytest.mark.parametrize(("param1", "param2"), [("value1", "value2")])
22+
@pytest.mark.tc_id(TEST_CASE_ID, parameterized=True, use_index=False)
23+
def test_case_id_decorator(param1, param2):
24+
assert True
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""A simple example test with Test Case ID decorator using parameter indices with selected params."""
2+
3+
# Copyright (c) 2023 https://reportportal.io .
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# https://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License
15+
16+
import pytest
17+
18+
TEST_CASE_ID = "ISSUE-USE-INDEX-PARTIAL"
19+
20+
21+
@pytest.mark.parametrize(("param1", "param2"), [("value1", "value2")])
22+
@pytest.mark.tc_id(TEST_CASE_ID, parameterized=True, params=["param1"], use_index=True)
23+
def test_case_id_decorator(param1, param2):
24+
assert True
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""A simple example test with Test Case ID decorator using parameter indices."""
2+
3+
# Copyright (c) 2023 https://reportportal.io .
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# https://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License
15+
16+
import pytest
17+
18+
TEST_CASE_ID = "ISSUE-USE-INDEX-TRUE"
19+
20+
21+
@pytest.mark.parametrize(("param1", "param2"), [("value1", "value2")])
22+
@pytest.mark.tc_id(TEST_CASE_ID, parameterized=True, use_index=True)
23+
def test_case_id_decorator(param1, param2):
24+
assert True
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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

Comments
 (0)