pytest-dsl 0.10.0__py3-none-any.whl → 0.11.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 +533 -89
- pytest_dsl/core/custom_keyword_manager.py +1 -4
- pytest_dsl/core/http_client.py +2 -2
- pytest_dsl/core/keyword_manager.py +77 -3
- pytest_dsl/core/plugin_discovery.py +38 -1
- pytest_dsl/keywords/http_keywords.py +90 -34
- pytest_dsl/remote/keyword_client.py +30 -17
- pytest_dsl/remote/keyword_server.py +18 -1
- pytest_dsl/remote/variable_bridge.py +41 -8
- pytest_dsl/templates/keywords_report.html +862 -0
- {pytest_dsl-0.10.0.dist-info → pytest_dsl-0.11.1.dist-info}/METADATA +2 -1
- {pytest_dsl-0.10.0.dist-info → pytest_dsl-0.11.1.dist-info}/RECORD +16 -15
- {pytest_dsl-0.10.0.dist-info → pytest_dsl-0.11.1.dist-info}/WHEEL +0 -0
- {pytest_dsl-0.10.0.dist-info → pytest_dsl-0.11.1.dist-info}/entry_points.txt +0 -0
- {pytest_dsl-0.10.0.dist-info → pytest_dsl-0.11.1.dist-info}/licenses/LICENSE +0 -0
- {pytest_dsl-0.10.0.dist-info → pytest_dsl-0.11.1.dist-info}/top_level.txt +0 -0
@@ -403,9 +403,26 @@ class RemoteKeywordServer:
|
|
403
403
|
self.shared_variables[name] = value
|
404
404
|
print(f"接收到客户端变量: {name}")
|
405
405
|
|
406
|
+
# 将所有同步的变量直接注入到yaml_vars中,实现无缝访问
|
407
|
+
from pytest_dsl.core.yaml_vars import yaml_vars
|
408
|
+
|
409
|
+
for name, value in variables.items():
|
410
|
+
# 直接设置到yaml_vars中,确保所有关键字都能无缝访问
|
411
|
+
yaml_vars._variables[name] = value
|
412
|
+
print(f"✓ 变量 {name} 已注入到yaml_vars,实现无缝访问")
|
413
|
+
|
414
|
+
# 同时处理全局变量到global_context
|
415
|
+
from pytest_dsl.core.global_context import global_context
|
416
|
+
for name, value in variables.items():
|
417
|
+
if name.startswith('g_'):
|
418
|
+
global_context.set_variable(name, value)
|
419
|
+
print(f"✓ 全局变量 {name} 已注入到global_context")
|
420
|
+
|
421
|
+
print(f"✅ 总共同步了 {len(variables)} 个变量,全部实现无缝访问")
|
422
|
+
|
406
423
|
return {
|
407
424
|
'status': 'success',
|
408
|
-
'message': f'成功同步 {len(variables)}
|
425
|
+
'message': f'成功同步 {len(variables)} 个变量,全部实现无缝访问'
|
409
426
|
}
|
410
427
|
except Exception as e:
|
411
428
|
return {
|
@@ -6,7 +6,8 @@
|
|
6
6
|
|
7
7
|
import logging
|
8
8
|
from typing import Any, Optional
|
9
|
-
from pytest_dsl.remote.hook_manager import register_startup_hook,
|
9
|
+
from pytest_dsl.remote.hook_manager import (register_startup_hook,
|
10
|
+
register_before_keyword_hook)
|
10
11
|
from pytest_dsl.core.yaml_vars import yaml_vars
|
11
12
|
from pytest_dsl.core.global_context import global_context
|
12
13
|
|
@@ -43,24 +44,28 @@ class VariableBridge:
|
|
43
44
|
|
44
45
|
self._bridge_installed = True
|
45
46
|
logger.info("变量桥接机制已安装")
|
47
|
+
print(f"🔗 变量桥接机制已安装,可桥接 {len(shared_variables)} 个同步变量")
|
46
48
|
|
47
49
|
def _bridged_yaml_get_variable(self, name: str) -> Optional[Any]:
|
48
50
|
"""桥接的YAML变量获取方法
|
49
51
|
|
50
52
|
优先级:
|
51
|
-
1. 原始YAML
|
53
|
+
1. 原始YAML变量(服务器本地的)
|
52
54
|
2. 客户端同步的变量
|
53
55
|
"""
|
54
56
|
# 首先尝试从原始YAML变量获取
|
55
57
|
original_value = self.original_yaml_get_variable(name)
|
56
58
|
if original_value is not None:
|
59
|
+
logger.debug(f"从原始YAML获取变量: {name}")
|
57
60
|
return original_value
|
58
61
|
|
59
62
|
# 如果原始YAML中没有,尝试从同步变量获取
|
60
63
|
if name in self.shared_variables:
|
61
64
|
logger.debug(f"从同步变量获取YAML变量: {name}")
|
65
|
+
print(f"🔗 变量桥接: 从同步变量获取 {name}")
|
62
66
|
return self.shared_variables[name]
|
63
67
|
|
68
|
+
logger.debug(f"变量 {name} 在原始YAML和同步变量中都不存在")
|
64
69
|
return None
|
65
70
|
|
66
71
|
def _bridged_global_get_variable(self, name: str) -> Any:
|
@@ -74,17 +79,20 @@ class VariableBridge:
|
|
74
79
|
# 首先尝试从原始全局上下文获取
|
75
80
|
original_value = self.original_global_get_variable(name)
|
76
81
|
if original_value is not None:
|
82
|
+
logger.debug(f"从原始全局上下文获取变量: {name}")
|
77
83
|
return original_value
|
78
|
-
except:
|
84
|
+
except Exception as e:
|
79
85
|
# 如果原始方法抛出异常,继续尝试同步变量
|
80
|
-
|
86
|
+
logger.debug(f"原始全局上下文获取变量 {name} 失败,尝试同步变量: {e}")
|
81
87
|
|
82
88
|
# 如果原始全局变量中没有,尝试从同步变量获取
|
83
89
|
if name in self.shared_variables:
|
84
90
|
logger.debug(f"从同步变量获取全局变量: {name}")
|
91
|
+
print(f"🔗 变量桥接: 从同步变量获取全局变量 {name}")
|
85
92
|
return self.shared_variables[name]
|
86
93
|
|
87
94
|
# 如果都没有找到,返回None(保持原有行为)
|
95
|
+
logger.debug(f"变量 {name} 在所有来源中都不存在")
|
88
96
|
return None
|
89
97
|
|
90
98
|
def uninstall_bridge(self):
|
@@ -113,6 +121,7 @@ def setup_variable_bridge(context):
|
|
113
121
|
if shared_variables is not None:
|
114
122
|
variable_bridge.install_bridge(shared_variables)
|
115
123
|
logger.info("变量桥接机制已在服务器启动时安装")
|
124
|
+
print(f"🔗 服务器启动时安装变量桥接机制,可桥接 {len(shared_variables)} 个变量")
|
116
125
|
else:
|
117
126
|
logger.warning("无法获取shared_variables,变量桥接机制安装失败")
|
118
127
|
|
@@ -124,11 +133,14 @@ def ensure_variable_bridge(context):
|
|
124
133
|
shared_variables = context.get('shared_variables')
|
125
134
|
keyword_name = context.get('keyword_name')
|
126
135
|
|
127
|
-
#
|
128
|
-
if
|
136
|
+
# 对所有关键字进行调试日志(如果有同步变量)
|
137
|
+
if shared_variables and len(shared_variables) > 0:
|
129
138
|
synced_count = len(shared_variables)
|
130
|
-
|
131
|
-
|
139
|
+
logger.debug(f"关键字 {keyword_name} 执行前,可用同步变量数量: {synced_count}")
|
140
|
+
|
141
|
+
# 对重要关键字显示详细信息
|
142
|
+
if keyword_name in ['HTTP请求', '数据库查询', 'API调用']:
|
143
|
+
print(f"🔗 关键字 {keyword_name} 可访问 {synced_count} 个同步变量")
|
132
144
|
|
133
145
|
|
134
146
|
def get_synced_variable(name: str) -> Optional[Any]:
|
@@ -162,3 +174,24 @@ def has_synced_variable(name: str) -> bool:
|
|
162
174
|
是否存在该同步变量
|
163
175
|
"""
|
164
176
|
return name in variable_bridge.shared_variables
|
177
|
+
|
178
|
+
|
179
|
+
def get_all_accessible_variables() -> dict:
|
180
|
+
"""获取所有可访问的变量(包括原始变量和同步变量)
|
181
|
+
|
182
|
+
Returns:
|
183
|
+
所有可访问变量的字典
|
184
|
+
"""
|
185
|
+
all_vars = {}
|
186
|
+
|
187
|
+
# 添加原始YAML变量
|
188
|
+
try:
|
189
|
+
if hasattr(yaml_vars, '_variables'):
|
190
|
+
all_vars.update(yaml_vars._variables)
|
191
|
+
except Exception as e:
|
192
|
+
logger.warning(f"获取原始YAML变量失败: {e}")
|
193
|
+
|
194
|
+
# 添加同步变量(会覆盖同名的原始变量)
|
195
|
+
all_vars.update(variable_bridge.shared_variables)
|
196
|
+
|
197
|
+
return all_vars
|