pytest-dsl 0.8.0__py3-none-any.whl → 0.9.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pytest_dsl/cli.py +362 -15
- pytest_dsl/core/custom_keyword_manager.py +49 -48
- pytest_dsl/core/dsl_executor.py +41 -11
- pytest_dsl/remote/__init__.py +7 -0
- pytest_dsl/remote/hook_manager.py +155 -0
- pytest_dsl/remote/keyword_client.py +376 -0
- pytest_dsl/remote/keyword_server.py +593 -0
- pytest_dsl/remote/variable_bridge.py +164 -0
- {pytest_dsl-0.8.0.dist-info → pytest_dsl-0.9.1.dist-info}/METADATA +1 -1
- {pytest_dsl-0.8.0.dist-info → pytest_dsl-0.9.1.dist-info}/RECORD +14 -9
- {pytest_dsl-0.8.0.dist-info → pytest_dsl-0.9.1.dist-info}/entry_points.txt +1 -0
- {pytest_dsl-0.8.0.dist-info → pytest_dsl-0.9.1.dist-info}/WHEEL +0 -0
- {pytest_dsl-0.8.0.dist-info → pytest_dsl-0.9.1.dist-info}/licenses/LICENSE +0 -0
- {pytest_dsl-0.8.0.dist-info → pytest_dsl-0.9.1.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,164 @@
|
|
1
|
+
"""远程服务器变量桥接模块
|
2
|
+
|
3
|
+
该模块提供了变量桥接机制,让远程服务器中的关键字能够无缝访问客户端同步的变量。
|
4
|
+
通过hook机制拦截变量访问,实现变量的透明传递。
|
5
|
+
"""
|
6
|
+
|
7
|
+
import logging
|
8
|
+
from typing import Any, Optional
|
9
|
+
from pytest_dsl.remote.hook_manager import register_startup_hook, register_before_keyword_hook
|
10
|
+
from pytest_dsl.core.yaml_vars import yaml_vars
|
11
|
+
from pytest_dsl.core.global_context import global_context
|
12
|
+
|
13
|
+
logger = logging.getLogger(__name__)
|
14
|
+
|
15
|
+
|
16
|
+
class VariableBridge:
|
17
|
+
"""变量桥接器,负责在远程服务器中桥接客户端同步的变量"""
|
18
|
+
|
19
|
+
def __init__(self):
|
20
|
+
self.shared_variables = {} # 引用远程服务器的shared_variables
|
21
|
+
self.original_yaml_get_variable = None
|
22
|
+
self.original_global_get_variable = None
|
23
|
+
self._bridge_installed = False
|
24
|
+
|
25
|
+
def install_bridge(self, shared_variables: dict):
|
26
|
+
"""安装变量桥接机制
|
27
|
+
|
28
|
+
Args:
|
29
|
+
shared_variables: 远程服务器的共享变量字典
|
30
|
+
"""
|
31
|
+
if self._bridge_installed:
|
32
|
+
return
|
33
|
+
|
34
|
+
self.shared_variables = shared_variables
|
35
|
+
|
36
|
+
# 备份原始方法
|
37
|
+
self.original_yaml_get_variable = yaml_vars.get_variable
|
38
|
+
self.original_global_get_variable = global_context.get_variable
|
39
|
+
|
40
|
+
# 安装桥接方法
|
41
|
+
yaml_vars.get_variable = self._bridged_yaml_get_variable
|
42
|
+
global_context.get_variable = self._bridged_global_get_variable
|
43
|
+
|
44
|
+
self._bridge_installed = True
|
45
|
+
logger.info("变量桥接机制已安装")
|
46
|
+
|
47
|
+
def _bridged_yaml_get_variable(self, name: str) -> Optional[Any]:
|
48
|
+
"""桥接的YAML变量获取方法
|
49
|
+
|
50
|
+
优先级:
|
51
|
+
1. 原始YAML变量
|
52
|
+
2. 客户端同步的变量
|
53
|
+
"""
|
54
|
+
# 首先尝试从原始YAML变量获取
|
55
|
+
original_value = self.original_yaml_get_variable(name)
|
56
|
+
if original_value is not None:
|
57
|
+
return original_value
|
58
|
+
|
59
|
+
# 如果原始YAML中没有,尝试从同步变量获取
|
60
|
+
if name in self.shared_variables:
|
61
|
+
logger.debug(f"从同步变量获取YAML变量: {name}")
|
62
|
+
return self.shared_variables[name]
|
63
|
+
|
64
|
+
return None
|
65
|
+
|
66
|
+
def _bridged_global_get_variable(self, name: str) -> Any:
|
67
|
+
"""桥接的全局变量获取方法
|
68
|
+
|
69
|
+
优先级:
|
70
|
+
1. 原始全局变量(包括YAML变量)
|
71
|
+
2. 客户端同步的变量
|
72
|
+
"""
|
73
|
+
try:
|
74
|
+
# 首先尝试从原始全局上下文获取
|
75
|
+
original_value = self.original_global_get_variable(name)
|
76
|
+
if original_value is not None:
|
77
|
+
return original_value
|
78
|
+
except:
|
79
|
+
# 如果原始方法抛出异常,继续尝试同步变量
|
80
|
+
pass
|
81
|
+
|
82
|
+
# 如果原始全局变量中没有,尝试从同步变量获取
|
83
|
+
if name in self.shared_variables:
|
84
|
+
logger.debug(f"从同步变量获取全局变量: {name}")
|
85
|
+
return self.shared_variables[name]
|
86
|
+
|
87
|
+
# 如果都没有找到,返回None(保持原有行为)
|
88
|
+
return None
|
89
|
+
|
90
|
+
def uninstall_bridge(self):
|
91
|
+
"""卸载变量桥接机制"""
|
92
|
+
if not self._bridge_installed:
|
93
|
+
return
|
94
|
+
|
95
|
+
# 恢复原始方法
|
96
|
+
if self.original_yaml_get_variable:
|
97
|
+
yaml_vars.get_variable = self.original_yaml_get_variable
|
98
|
+
if self.original_global_get_variable:
|
99
|
+
global_context.get_variable = self.original_global_get_variable
|
100
|
+
|
101
|
+
self._bridge_installed = False
|
102
|
+
logger.info("变量桥接机制已卸载")
|
103
|
+
|
104
|
+
|
105
|
+
# 全局变量桥接器实例
|
106
|
+
variable_bridge = VariableBridge()
|
107
|
+
|
108
|
+
|
109
|
+
@register_startup_hook
|
110
|
+
def setup_variable_bridge(context):
|
111
|
+
"""服务器启动时安装变量桥接机制"""
|
112
|
+
shared_variables = context.get('shared_variables')
|
113
|
+
if shared_variables is not None:
|
114
|
+
variable_bridge.install_bridge(shared_variables)
|
115
|
+
logger.info("变量桥接机制已在服务器启动时安装")
|
116
|
+
else:
|
117
|
+
logger.warning("无法获取shared_variables,变量桥接机制安装失败")
|
118
|
+
|
119
|
+
|
120
|
+
@register_before_keyword_hook
|
121
|
+
def ensure_variable_bridge(context):
|
122
|
+
"""关键字执行前确保变量桥接机制正常工作"""
|
123
|
+
# 这个hook主要用于调试和监控
|
124
|
+
shared_variables = context.get('shared_variables')
|
125
|
+
keyword_name = context.get('keyword_name')
|
126
|
+
|
127
|
+
# 只对特定关键字进行调试日志
|
128
|
+
if keyword_name in ['HTTP请求', '数据库查询'] and shared_variables:
|
129
|
+
synced_count = len(shared_variables)
|
130
|
+
if synced_count > 0:
|
131
|
+
logger.debug(f"关键字 {keyword_name} 执行前,可用同步变量数量: {synced_count}")
|
132
|
+
|
133
|
+
|
134
|
+
def get_synced_variable(name: str) -> Optional[Any]:
|
135
|
+
"""直接从同步变量中获取变量值
|
136
|
+
|
137
|
+
Args:
|
138
|
+
name: 变量名
|
139
|
+
|
140
|
+
Returns:
|
141
|
+
变量值,如果不存在则返回None
|
142
|
+
"""
|
143
|
+
return variable_bridge.shared_variables.get(name)
|
144
|
+
|
145
|
+
|
146
|
+
def list_synced_variables() -> dict:
|
147
|
+
"""列出所有同步的变量
|
148
|
+
|
149
|
+
Returns:
|
150
|
+
同步变量字典的副本
|
151
|
+
"""
|
152
|
+
return variable_bridge.shared_variables.copy()
|
153
|
+
|
154
|
+
|
155
|
+
def has_synced_variable(name: str) -> bool:
|
156
|
+
"""检查是否存在指定的同步变量
|
157
|
+
|
158
|
+
Args:
|
159
|
+
name: 变量名
|
160
|
+
|
161
|
+
Returns:
|
162
|
+
是否存在该同步变量
|
163
|
+
"""
|
164
|
+
return name in variable_bridge.shared_variables
|
@@ -1,5 +1,5 @@
|
|
1
1
|
pytest_dsl/__init__.py,sha256=FzwXGvmuvMhRBKxvCdh1h-yJ2wUOnDxcTbU4Nt5fHn8,301
|
2
|
-
pytest_dsl/cli.py,sha256=
|
2
|
+
pytest_dsl/cli.py,sha256=x3zSHJqAGUNPUsJfhFRzVVwRE0zM02Lcr2bx_V8v4YA,15806
|
3
3
|
pytest_dsl/conftest_adapter.py,sha256=cevEb0oEZKTZfUrGe1-CmkFByxKhUtjuurBJP7kpLc0,149
|
4
4
|
pytest_dsl/main_adapter.py,sha256=pUIPN_EzY3JCDlYK7yF_OeLDVqni8vtG15G7gVzPJXg,181
|
5
5
|
pytest_dsl/plugin.py,sha256=MEQcdK0xdxwxCxPEDLNHX_kGF9Jc7bNxlNi4mx588DU,1190
|
@@ -8,8 +8,8 @@ pytest_dsl/core/auth_provider.py,sha256=IZfXXrr4Uuc8QHwRPvhHSzNa2fwrqhjYts1xh78D
|
|
8
8
|
pytest_dsl/core/auto_decorator.py,sha256=9Mga-GB4AzV5nkB6zpfaq8IuHa0KOH8LlFvnWyH_tnU,6623
|
9
9
|
pytest_dsl/core/auto_directory.py,sha256=egyTnVxtGs4P75EIivRauLRPJfN9aZpoGVvp_Ma72AM,2714
|
10
10
|
pytest_dsl/core/context.py,sha256=fXpVQon666Lz_PCexjkWMBBr-Xcd1SkDMp2vHar6eIs,664
|
11
|
-
pytest_dsl/core/custom_keyword_manager.py,sha256=
|
12
|
-
pytest_dsl/core/dsl_executor.py,sha256
|
11
|
+
pytest_dsl/core/custom_keyword_manager.py,sha256=Y3MftSklqGSS3FfeZjmyfcGHfQw6FrhFTwgS_O8zQh4,7606
|
12
|
+
pytest_dsl/core/dsl_executor.py,sha256=aEEfocFCFxNDN1puBFhQzL5fzw9eZx8BAyYJI5XSt4Y,30472
|
13
13
|
pytest_dsl/core/dsl_executor_utils.py,sha256=cFoR2p3qQ2pb-UhkoefleK-zbuFqf0aBLh2Rlp8Ebs4,2180
|
14
14
|
pytest_dsl/core/global_context.py,sha256=NcEcS2V61MT70tgAsGsFWQq0P3mKjtHQr1rgT3yTcyY,3535
|
15
15
|
pytest_dsl/core/http_client.py,sha256=1AHqtM_fkXf8JrM0ljMsJwUkyt-ysjR16NoyCckHfGc,15810
|
@@ -59,9 +59,14 @@ pytest_dsl/keywords/assertion_keywords.py,sha256=WOCGP7WX2wZ6mQPDGmi38LWdG2NaThH
|
|
59
59
|
pytest_dsl/keywords/global_keywords.py,sha256=4yw5yeXoGf_4W26F39EA2Pp-mH9GiKGy2jKgFO9a_wM,2509
|
60
60
|
pytest_dsl/keywords/http_keywords.py,sha256=DY1SvUgOziN6Ga-QgE0q4XFd2qGGwvbv1B_k2gTdPLw,25554
|
61
61
|
pytest_dsl/keywords/system_keywords.py,sha256=n_jRrMvSv2v6Pm_amokfyLNVOLYP7CFWbBE3_dlO7h4,11299
|
62
|
-
pytest_dsl
|
63
|
-
pytest_dsl
|
64
|
-
pytest_dsl
|
65
|
-
pytest_dsl
|
66
|
-
pytest_dsl
|
67
|
-
pytest_dsl-0.
|
62
|
+
pytest_dsl/remote/__init__.py,sha256=syRSxTlTUfdAPleJnVS4MykRyEN8_SKiqlsn6SlIK8k,120
|
63
|
+
pytest_dsl/remote/hook_manager.py,sha256=0hwRKP8yhcnfAnrrnZGVT-S0TBgo6c0A4qO5XRpvV1U,4899
|
64
|
+
pytest_dsl/remote/keyword_client.py,sha256=Zem86qW6TudPAiiqU8wAFQeCoBl5urPRiAhFDPkAGgQ,15618
|
65
|
+
pytest_dsl/remote/keyword_server.py,sha256=5nKLUIqgAVJoLL2t2dHaJb9S95z4K3UusSMEBylU6X4,20549
|
66
|
+
pytest_dsl/remote/variable_bridge.py,sha256=KG2xTZcUExb8kNL-rR-IPFJmYGfo7ciE4W7xzet59sw,5520
|
67
|
+
pytest_dsl-0.9.1.dist-info/licenses/LICENSE,sha256=Rguy8cb9sYhK6cmrBdXvwh94rKVDh2tVZEWptsHIsVM,1071
|
68
|
+
pytest_dsl-0.9.1.dist-info/METADATA,sha256=tmPXjA1YZtuduO_Fus6vujf1vMOYxx3L2n7c7ZV4oyc,26712
|
69
|
+
pytest_dsl-0.9.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
70
|
+
pytest_dsl-0.9.1.dist-info/entry_points.txt,sha256=PLOBbH02OGY1XR1JDKIZB1Em87loUvbgMRWaag-5FhY,204
|
71
|
+
pytest_dsl-0.9.1.dist-info/top_level.txt,sha256=4CrSx4uNqxj7NvK6k1y2JZrSrJSzi-UvPZdqpUhumWM,11
|
72
|
+
pytest_dsl-0.9.1.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|