-
Notifications
You must be signed in to change notification settings - Fork 107
Expand file tree
/
Copy pathtest_service.py
More file actions
87 lines (58 loc) · 3 KB
/
test_service.py
File metadata and controls
87 lines (58 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# Copyright (c) 2023 https://reportportal.io .
# 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
"""This module includes unit tests for the service.py module."""
import os
from delayed_assert import assert_expectations, expect
from pytest_reportportal.service import _is_pytest_bdd_scenario
def test_is_pytest_bdd_scenario_path():
"""pytest-bdd scenario items use forward slashes in location on POSIX and backslashes on Windows."""
path = os.path.join("project", "pytest_bdd", "scenario.py")
assert _is_pytest_bdd_scenario(path) is True
def test_is_pytest_bdd_scenario_regular_test_module():
"""Regular tests must not be treated as pytest-bdd scenario glue."""
assert _is_pytest_bdd_scenario("/project/tests/test_foo.py") is False
def test_get_item_parameters(mocked_item, rp_service):
"""Test that parameters are returned in a way supported by the client."""
mocked_item.callspec.params = {"param": "param_value"}
expect(rp_service._get_parameters(mocked_item) == {"param": "param_value"})
delattr(mocked_item, "callspec")
expect(rp_service._get_parameters(mocked_item) is None)
assert_expectations()
def test_get_method_name_regular(mocked_item, rp_service):
"""Test that regular test names are returned as-is."""
mocked_item.name = "test_simple_function"
mocked_item.originalname = None
result = rp_service._get_method_name(mocked_item)
expect(result == "test_simple_function")
assert_expectations()
def test_get_method_name_uses_originalname(mocked_item, rp_service):
"""Test that originalname is preferred when available."""
mocked_item.name = "test_verify_data[Daily]@sync_group"
mocked_item.originalname = "test_verify_data"
result = rp_service._get_method_name(mocked_item)
expect(result == "test_verify_data")
assert_expectations()
def test_get_method_name_strips_suffix(mocked_item, rp_service):
"""Test that trailing @suffix is stripped when originalname is None."""
mocked_item.name = "test_export_data@data_export"
mocked_item.originalname = None
result = rp_service._get_method_name(mocked_item)
expect(result == "test_export_data")
assert_expectations()
def test_get_method_name_preserves_at_inside_params(mocked_item, rp_service):
"""Test that @ inside parameter brackets is preserved."""
mocked_item.name = "test_email[user@example.com]"
mocked_item.originalname = None
result = rp_service._get_method_name(mocked_item)
expect(result == "test_email[user@example.com]")
assert_expectations()