pytest-dsl 0.9.1__tar.gz → 0.11.0__tar.gz
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-0.9.1 → pytest_dsl-0.11.0}/MANIFEST.in +1 -0
- {pytest_dsl-0.9.1/pytest_dsl.egg-info → pytest_dsl-0.11.0}/PKG-INFO +89 -23
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/README.md +87 -22
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/pyproject.toml +2 -1
- pytest_dsl-0.11.0/pytest_dsl/cli.py +977 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/pytest_dsl/core/custom_keyword_manager.py +1 -4
- pytest_dsl-0.11.0/pytest_dsl/core/keyword_manager.py +199 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/pytest_dsl/core/plugin_discovery.py +38 -1
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/pytest_dsl/keywords/assertion_keywords.py +18 -12
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/pytest_dsl/keywords/http_keywords.py +4 -4
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/pytest_dsl/keywords/system_keywords.py +73 -48
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/pytest_dsl/remote/keyword_client.py +32 -9
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/pytest_dsl/remote/keyword_server.py +25 -0
- pytest_dsl-0.11.0/pytest_dsl/templates/keywords_report.html +862 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0/pytest_dsl.egg-info}/PKG-INFO +89 -23
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/pytest_dsl.egg-info/SOURCES.txt +1 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/pytest_dsl.egg-info/requires.txt +1 -0
- pytest_dsl-0.9.1/pytest_dsl/cli.py +0 -485
- pytest_dsl-0.9.1/pytest_dsl/core/keyword_manager.py +0 -109
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/LICENSE +0 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/pytest_dsl/__init__.py +0 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/pytest_dsl/conftest_adapter.py +0 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/pytest_dsl/core/__init__.py +0 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/pytest_dsl/core/auth_provider.py +0 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/pytest_dsl/core/auto_decorator.py +0 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/pytest_dsl/core/auto_directory.py +0 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/pytest_dsl/core/context.py +0 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/pytest_dsl/core/dsl_executor.py +0 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/pytest_dsl/core/dsl_executor_utils.py +0 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/pytest_dsl/core/global_context.py +0 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/pytest_dsl/core/http_client.py +0 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/pytest_dsl/core/http_request.py +0 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/pytest_dsl/core/lexer.py +0 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/pytest_dsl/core/parser.py +0 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/pytest_dsl/core/parsetab.py +0 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/pytest_dsl/core/utils.py +0 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/pytest_dsl/core/variable_utils.py +0 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/pytest_dsl/core/yaml_loader.py +0 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/pytest_dsl/core/yaml_vars.py +0 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/pytest_dsl/docs/custom_keywords.md +0 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/pytest_dsl/examples/__init__.py +0 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/pytest_dsl/examples/assert/assertion_example.auto +0 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/pytest_dsl/examples/assert/boolean_test.auto +0 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/pytest_dsl/examples/assert/expression_test.auto +0 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/pytest_dsl/examples/custom/test_advanced_keywords.auto +0 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/pytest_dsl/examples/custom/test_custom_keywords.auto +0 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/pytest_dsl/examples/custom/test_default_values.auto +0 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/pytest_dsl/examples/http/__init__.py +0 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/pytest_dsl/examples/http/builtin_auth_test.auto +0 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/pytest_dsl/examples/http/file_reference_test.auto +0 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/pytest_dsl/examples/http/http_advanced.auto +0 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/pytest_dsl/examples/http/http_example.auto +0 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/pytest_dsl/examples/http/http_length_test.auto +0 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/pytest_dsl/examples/http/http_retry_assertions.auto +0 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/pytest_dsl/examples/http/http_retry_assertions_enhanced.auto +0 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/pytest_dsl/examples/http/http_with_yaml.auto +0 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/pytest_dsl/examples/http/new_retry_test.auto +0 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/pytest_dsl/examples/http/retry_assertions_only.auto +0 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/pytest_dsl/examples/http/retry_config_only.auto +0 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/pytest_dsl/examples/http/retry_debug.auto +0 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/pytest_dsl/examples/http/retry_with_fix.auto +0 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/pytest_dsl/examples/http/simple_retry.auto +0 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/pytest_dsl/examples/http/vars.yaml +0 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/pytest_dsl/examples/quickstart/api_basics.auto +0 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/pytest_dsl/examples/quickstart/assertions.auto +0 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/pytest_dsl/examples/quickstart/loops.auto +0 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/pytest_dsl/examples/test_assert.py +0 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/pytest_dsl/examples/test_custom_keyword.py +0 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/pytest_dsl/examples/test_http.py +0 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/pytest_dsl/examples/test_quickstart.py +0 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/pytest_dsl/keywords/__init__.py +0 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/pytest_dsl/keywords/global_keywords.py +0 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/pytest_dsl/main_adapter.py +0 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/pytest_dsl/plugin.py +0 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/pytest_dsl/remote/__init__.py +0 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/pytest_dsl/remote/hook_manager.py +0 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/pytest_dsl/remote/variable_bridge.py +0 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/pytest_dsl.egg-info/dependency_links.txt +0 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/pytest_dsl.egg-info/entry_points.txt +0 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/pytest_dsl.egg-info/top_level.txt +0 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/setup.cfg +0 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/setup.py +0 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/tests/test_end_to_end_seamless.py +0 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/tests/test_enhanced_variable_access.py +0 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/tests/test_http_assertions_extractors.py +0 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/tests/test_seamless_variable_sync.py +0 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/tests/test_variable_sync.py +0 -0
- {pytest_dsl-0.9.1 → pytest_dsl-0.11.0}/tests/test_variable_sync_demo.py +0 -0
@@ -5,6 +5,7 @@ include MANIFEST.in
|
|
5
5
|
|
6
6
|
recursive-include pytest_dsl/examples *.auto *.csv *.yaml *.yml
|
7
7
|
recursive-include pytest_dsl/docs *.md *.rst *.txt *.png *.jpg
|
8
|
+
recursive-include pytest_dsl/templates *.html
|
8
9
|
recursive-include tests *.py *.auto *.csv *.yaml *.yml
|
9
10
|
|
10
11
|
prune .venv
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: pytest-dsl
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.11.0
|
4
4
|
Summary: A DSL testing framework based on pytest
|
5
5
|
Author: Chen Shuanglin
|
6
6
|
License: MIT
|
@@ -27,6 +27,7 @@ Requires-Dist: requests>=2.28.0
|
|
27
27
|
Requires-Dist: lxml>=4.9.0
|
28
28
|
Requires-Dist: jsonschema>=4.17.0
|
29
29
|
Requires-Dist: pytz>=2023.3
|
30
|
+
Requires-Dist: Jinja2>=3.0.0
|
30
31
|
Dynamic: license-file
|
31
32
|
|
32
33
|
# pytest-dsl: 强大的关键字驱动测试自动化框架
|
@@ -42,11 +43,12 @@ pytest-dsl是一个革命性的关键字驱动测试框架,基于pytest构建
|
|
42
43
|
## ✨ 核心特性
|
43
44
|
|
44
45
|
- 🎯 **门槛上手低** - 自然语言风格,只需少量编程基础
|
45
|
-
- 🔧 **高度可扩展** -
|
46
|
+
- 🔧 **高度可扩展** - 轻松创建自定义关键字,支持参数默认值
|
46
47
|
- 🌐 **分布式执行** - 支持远程关键字调用
|
47
48
|
- 🔄 **无缝集成** - 完美兼容pytest生态
|
48
49
|
- 📊 **丰富报告** - 集成Allure测试报告
|
49
50
|
- 🛡️ **企业级** - 支持变量管理、环境隔离
|
51
|
+
- ⚡ **智能简化** - 参数默认值让DSL更加简洁易读
|
50
52
|
|
51
53
|
## 🚀 5分钟快速开始
|
52
54
|
|
@@ -850,17 +852,19 @@ def database_query(**kwargs):
|
|
850
852
|
|
851
853
|
@keyword_manager.register('发送邮件', [
|
852
854
|
{'name': '收件人', 'mapping': 'to_email', 'description': '收件人邮箱'},
|
853
|
-
{'name': '主题', 'mapping': 'subject', 'description': '邮件主题'},
|
854
|
-
{'name': '内容', 'mapping': 'content', 'description': '邮件内容'}
|
855
|
+
{'name': '主题', 'mapping': 'subject', 'description': '邮件主题', 'default': '测试邮件'},
|
856
|
+
{'name': '内容', 'mapping': 'content', 'description': '邮件内容', 'default': '这是一封测试邮件'},
|
857
|
+
{'name': '优先级', 'mapping': 'priority', 'description': '邮件优先级', 'default': 'normal'}
|
855
858
|
])
|
856
859
|
def send_email(**kwargs):
|
857
860
|
"""发送邮件通知"""
|
858
861
|
to_email = kwargs.get('to_email')
|
859
|
-
subject = kwargs.get('subject')
|
860
|
-
content = kwargs.get('content')
|
862
|
+
subject = kwargs.get('subject', '测试邮件')
|
863
|
+
content = kwargs.get('content', '这是一封测试邮件')
|
864
|
+
priority = kwargs.get('priority', 'normal')
|
861
865
|
|
862
866
|
# 实现邮件发送逻辑
|
863
|
-
print(f"发送邮件到 {to_email}: {subject}")
|
867
|
+
print(f"发送邮件到 {to_email}: {subject} (优先级: {priority})")
|
864
868
|
|
865
869
|
return True
|
866
870
|
```
|
@@ -874,10 +878,71 @@ def send_email(**kwargs):
|
|
874
878
|
users = [数据库查询], 查询语句: "SELECT * FROM users WHERE active = 1"
|
875
879
|
[打印], 内容: "查询到 ${len(users)} 个活跃用户"
|
876
880
|
|
877
|
-
# 发送测试报告邮件
|
878
|
-
[发送邮件], 收件人: "admin@example.com"
|
881
|
+
# 发送测试报告邮件 - 使用默认值
|
882
|
+
[发送邮件], 收件人: "admin@example.com" # 主题和内容使用默认值
|
883
|
+
|
884
|
+
# 发送自定义邮件 - 覆盖默认值
|
885
|
+
[发送邮件], 收件人: "dev@example.com", 主题: "部署完成", 内容: "系统已成功部署到生产环境"
|
886
|
+
```
|
887
|
+
|
888
|
+
### 5. 参数默认值功能 🆕
|
889
|
+
|
890
|
+
pytest-dsl 现在支持为关键字参数设置默认值,让DSL编写更加简洁:
|
891
|
+
|
892
|
+
#### 定义带默认值的关键字
|
893
|
+
|
894
|
+
```python
|
895
|
+
from pytest_dsl.core.keyword_manager import keyword_manager
|
896
|
+
|
897
|
+
@keyword_manager.register('HTTP请求', [
|
898
|
+
{'name': '地址', 'mapping': 'url', 'description': '请求地址'},
|
899
|
+
{'name': '方法', 'mapping': 'method', 'description': 'HTTP方法', 'default': 'GET'},
|
900
|
+
{'name': '超时', 'mapping': 'timeout', 'description': '超时时间(秒)', 'default': 30},
|
901
|
+
{'name': '重试次数', 'mapping': 'retries', 'description': '重试次数', 'default': 3},
|
902
|
+
{'name': '验证SSL', 'mapping': 'verify_ssl', 'description': '是否验证SSL证书', 'default': True}
|
903
|
+
])
|
904
|
+
def http_request(**kwargs):
|
905
|
+
"""HTTP请求关键字,支持默认值"""
|
906
|
+
url = kwargs.get('url')
|
907
|
+
method = kwargs.get('method', 'GET') # 默认值也会自动应用
|
908
|
+
timeout = kwargs.get('timeout', 30)
|
909
|
+
retries = kwargs.get('retries', 3)
|
910
|
+
verify_ssl = kwargs.get('verify_ssl', True)
|
911
|
+
|
912
|
+
# 执行HTTP请求逻辑
|
913
|
+
return {"status": "success", "method": method, "url": url}
|
879
914
|
```
|
880
915
|
|
916
|
+
#### 在DSL中使用默认值
|
917
|
+
|
918
|
+
```python
|
919
|
+
@name: "默认值功能演示"
|
920
|
+
|
921
|
+
# 只传递必需参数,其他使用默认值
|
922
|
+
response1 = [HTTP请求], 地址: "https://api.example.com/users"
|
923
|
+
# 等价于:方法: "GET", 超时: 30, 重试次数: 3, 验证SSL: True
|
924
|
+
|
925
|
+
# 部分覆盖默认值
|
926
|
+
response2 = [HTTP请求], 地址: "https://api.example.com/users", 方法: "POST", 超时: 60
|
927
|
+
# 只覆盖方法和超时,重试次数和SSL验证仍使用默认值
|
928
|
+
|
929
|
+
# 内置关键字也支持默认值
|
930
|
+
random_num = [生成随机数] # 使用默认范围 0-100,整数
|
931
|
+
custom_num = [生成随机数], 最大值: 50 # 只修改最大值,其他保持默认
|
932
|
+
|
933
|
+
# 生成随机字符串
|
934
|
+
default_string = [生成随机字符串] # 长度8,字母数字混合
|
935
|
+
custom_string = [生成随机字符串], 长度: 12, 类型: "letters" # 自定义长度和类型
|
936
|
+
```
|
937
|
+
|
938
|
+
#### 默认值的优势
|
939
|
+
|
940
|
+
- **🎯 简化调用** - 只需传递关键参数,常用配置自动应用
|
941
|
+
- **🔧 灵活覆盖** - 可选择性地覆盖任何默认值
|
942
|
+
- **📖 提高可读性** - DSL更加简洁,重点突出
|
943
|
+
- **🛡️ 减少错误** - 避免重复配置常用参数
|
944
|
+
- **🌐 远程支持** - 远程关键字也完整支持默认值功能
|
945
|
+
|
881
946
|
#### 支持远程模式的关键字
|
882
947
|
|
883
948
|
```python
|
@@ -1037,20 +1102,6 @@ CMD ["pytest-dsl", "tests/", "--yaml-vars", "config/prod.yaml"]
|
|
1037
1102
|
- **集成测试** - 跨系统测试协调
|
1038
1103
|
- **性能测试** - 结合其他工具进行性能测试
|
1039
1104
|
|
1040
|
-
## 🤝 贡献与支持
|
1041
|
-
|
1042
|
-
我们欢迎您的贡献和反馈!
|
1043
|
-
|
1044
|
-
- 🐛 [报告问题](https://github.com/your-repo/pytest-dsl/issues)
|
1045
|
-
- 💡 [功能建议](https://github.com/your-repo/pytest-dsl/discussions)
|
1046
|
-
- 🔧 [提交PR](https://github.com/your-repo/pytest-dsl/pulls)
|
1047
|
-
|
1048
|
-
## 📄 许可证
|
1049
|
-
|
1050
|
-
MIT License - 详见 [LICENSE](LICENSE) 文件
|
1051
|
-
|
1052
|
-
---
|
1053
|
-
|
1054
1105
|
## 📋 示例验证
|
1055
1106
|
|
1056
1107
|
本README.md中的大部分示例都已经过验证,确保可以正常运行。验证示例位于 `examples/readme_validation/` 目录中。
|
@@ -1086,3 +1137,18 @@ pytest-dsl api_basic.dsl
|
|
1086
1137
|
---
|
1087
1138
|
|
1088
1139
|
🚀 **开始使用pytest-dsl,让测试自动化变得简单而强大!**
|
1140
|
+
|
1141
|
+
|
1142
|
+
## 🤝 贡献与支持
|
1143
|
+
|
1144
|
+
我们欢迎您的贡献和反馈!
|
1145
|
+
|
1146
|
+
- 🐛 [报告问题](https://github.com/felix-1991/pytest-dsl/issues)
|
1147
|
+
- 💡 [功能建议](https://github.com/felix-1991/pytest-dsl/discussions)
|
1148
|
+
- 🔧 [提交PR](https://github.com/felix-1991/pytest-dsl/pulls)
|
1149
|
+
|
1150
|
+
## 📄 许可证
|
1151
|
+
|
1152
|
+
MIT License - 详见 [LICENSE](LICENSE) 文件
|
1153
|
+
|
1154
|
+
---
|
@@ -11,11 +11,12 @@ pytest-dsl是一个革命性的关键字驱动测试框架,基于pytest构建
|
|
11
11
|
## ✨ 核心特性
|
12
12
|
|
13
13
|
- 🎯 **门槛上手低** - 自然语言风格,只需少量编程基础
|
14
|
-
- 🔧 **高度可扩展** -
|
14
|
+
- 🔧 **高度可扩展** - 轻松创建自定义关键字,支持参数默认值
|
15
15
|
- 🌐 **分布式执行** - 支持远程关键字调用
|
16
16
|
- 🔄 **无缝集成** - 完美兼容pytest生态
|
17
17
|
- 📊 **丰富报告** - 集成Allure测试报告
|
18
18
|
- 🛡️ **企业级** - 支持变量管理、环境隔离
|
19
|
+
- ⚡ **智能简化** - 参数默认值让DSL更加简洁易读
|
19
20
|
|
20
21
|
## 🚀 5分钟快速开始
|
21
22
|
|
@@ -819,17 +820,19 @@ def database_query(**kwargs):
|
|
819
820
|
|
820
821
|
@keyword_manager.register('发送邮件', [
|
821
822
|
{'name': '收件人', 'mapping': 'to_email', 'description': '收件人邮箱'},
|
822
|
-
{'name': '主题', 'mapping': 'subject', 'description': '邮件主题'},
|
823
|
-
{'name': '内容', 'mapping': 'content', 'description': '邮件内容'}
|
823
|
+
{'name': '主题', 'mapping': 'subject', 'description': '邮件主题', 'default': '测试邮件'},
|
824
|
+
{'name': '内容', 'mapping': 'content', 'description': '邮件内容', 'default': '这是一封测试邮件'},
|
825
|
+
{'name': '优先级', 'mapping': 'priority', 'description': '邮件优先级', 'default': 'normal'}
|
824
826
|
])
|
825
827
|
def send_email(**kwargs):
|
826
828
|
"""发送邮件通知"""
|
827
829
|
to_email = kwargs.get('to_email')
|
828
|
-
subject = kwargs.get('subject')
|
829
|
-
content = kwargs.get('content')
|
830
|
+
subject = kwargs.get('subject', '测试邮件')
|
831
|
+
content = kwargs.get('content', '这是一封测试邮件')
|
832
|
+
priority = kwargs.get('priority', 'normal')
|
830
833
|
|
831
834
|
# 实现邮件发送逻辑
|
832
|
-
print(f"发送邮件到 {to_email}: {subject}")
|
835
|
+
print(f"发送邮件到 {to_email}: {subject} (优先级: {priority})")
|
833
836
|
|
834
837
|
return True
|
835
838
|
```
|
@@ -843,10 +846,71 @@ def send_email(**kwargs):
|
|
843
846
|
users = [数据库查询], 查询语句: "SELECT * FROM users WHERE active = 1"
|
844
847
|
[打印], 内容: "查询到 ${len(users)} 个活跃用户"
|
845
848
|
|
846
|
-
# 发送测试报告邮件
|
847
|
-
[发送邮件], 收件人: "admin@example.com"
|
849
|
+
# 发送测试报告邮件 - 使用默认值
|
850
|
+
[发送邮件], 收件人: "admin@example.com" # 主题和内容使用默认值
|
851
|
+
|
852
|
+
# 发送自定义邮件 - 覆盖默认值
|
853
|
+
[发送邮件], 收件人: "dev@example.com", 主题: "部署完成", 内容: "系统已成功部署到生产环境"
|
854
|
+
```
|
855
|
+
|
856
|
+
### 5. 参数默认值功能 🆕
|
857
|
+
|
858
|
+
pytest-dsl 现在支持为关键字参数设置默认值,让DSL编写更加简洁:
|
859
|
+
|
860
|
+
#### 定义带默认值的关键字
|
861
|
+
|
862
|
+
```python
|
863
|
+
from pytest_dsl.core.keyword_manager import keyword_manager
|
864
|
+
|
865
|
+
@keyword_manager.register('HTTP请求', [
|
866
|
+
{'name': '地址', 'mapping': 'url', 'description': '请求地址'},
|
867
|
+
{'name': '方法', 'mapping': 'method', 'description': 'HTTP方法', 'default': 'GET'},
|
868
|
+
{'name': '超时', 'mapping': 'timeout', 'description': '超时时间(秒)', 'default': 30},
|
869
|
+
{'name': '重试次数', 'mapping': 'retries', 'description': '重试次数', 'default': 3},
|
870
|
+
{'name': '验证SSL', 'mapping': 'verify_ssl', 'description': '是否验证SSL证书', 'default': True}
|
871
|
+
])
|
872
|
+
def http_request(**kwargs):
|
873
|
+
"""HTTP请求关键字,支持默认值"""
|
874
|
+
url = kwargs.get('url')
|
875
|
+
method = kwargs.get('method', 'GET') # 默认值也会自动应用
|
876
|
+
timeout = kwargs.get('timeout', 30)
|
877
|
+
retries = kwargs.get('retries', 3)
|
878
|
+
verify_ssl = kwargs.get('verify_ssl', True)
|
879
|
+
|
880
|
+
# 执行HTTP请求逻辑
|
881
|
+
return {"status": "success", "method": method, "url": url}
|
848
882
|
```
|
849
883
|
|
884
|
+
#### 在DSL中使用默认值
|
885
|
+
|
886
|
+
```python
|
887
|
+
@name: "默认值功能演示"
|
888
|
+
|
889
|
+
# 只传递必需参数,其他使用默认值
|
890
|
+
response1 = [HTTP请求], 地址: "https://api.example.com/users"
|
891
|
+
# 等价于:方法: "GET", 超时: 30, 重试次数: 3, 验证SSL: True
|
892
|
+
|
893
|
+
# 部分覆盖默认值
|
894
|
+
response2 = [HTTP请求], 地址: "https://api.example.com/users", 方法: "POST", 超时: 60
|
895
|
+
# 只覆盖方法和超时,重试次数和SSL验证仍使用默认值
|
896
|
+
|
897
|
+
# 内置关键字也支持默认值
|
898
|
+
random_num = [生成随机数] # 使用默认范围 0-100,整数
|
899
|
+
custom_num = [生成随机数], 最大值: 50 # 只修改最大值,其他保持默认
|
900
|
+
|
901
|
+
# 生成随机字符串
|
902
|
+
default_string = [生成随机字符串] # 长度8,字母数字混合
|
903
|
+
custom_string = [生成随机字符串], 长度: 12, 类型: "letters" # 自定义长度和类型
|
904
|
+
```
|
905
|
+
|
906
|
+
#### 默认值的优势
|
907
|
+
|
908
|
+
- **🎯 简化调用** - 只需传递关键参数,常用配置自动应用
|
909
|
+
- **🔧 灵活覆盖** - 可选择性地覆盖任何默认值
|
910
|
+
- **📖 提高可读性** - DSL更加简洁,重点突出
|
911
|
+
- **🛡️ 减少错误** - 避免重复配置常用参数
|
912
|
+
- **🌐 远程支持** - 远程关键字也完整支持默认值功能
|
913
|
+
|
850
914
|
#### 支持远程模式的关键字
|
851
915
|
|
852
916
|
```python
|
@@ -1006,20 +1070,6 @@ CMD ["pytest-dsl", "tests/", "--yaml-vars", "config/prod.yaml"]
|
|
1006
1070
|
- **集成测试** - 跨系统测试协调
|
1007
1071
|
- **性能测试** - 结合其他工具进行性能测试
|
1008
1072
|
|
1009
|
-
## 🤝 贡献与支持
|
1010
|
-
|
1011
|
-
我们欢迎您的贡献和反馈!
|
1012
|
-
|
1013
|
-
- 🐛 [报告问题](https://github.com/your-repo/pytest-dsl/issues)
|
1014
|
-
- 💡 [功能建议](https://github.com/your-repo/pytest-dsl/discussions)
|
1015
|
-
- 🔧 [提交PR](https://github.com/your-repo/pytest-dsl/pulls)
|
1016
|
-
|
1017
|
-
## 📄 许可证
|
1018
|
-
|
1019
|
-
MIT License - 详见 [LICENSE](LICENSE) 文件
|
1020
|
-
|
1021
|
-
---
|
1022
|
-
|
1023
1073
|
## 📋 示例验证
|
1024
1074
|
|
1025
1075
|
本README.md中的大部分示例都已经过验证,确保可以正常运行。验证示例位于 `examples/readme_validation/` 目录中。
|
@@ -1055,3 +1105,18 @@ pytest-dsl api_basic.dsl
|
|
1055
1105
|
---
|
1056
1106
|
|
1057
1107
|
🚀 **开始使用pytest-dsl,让测试自动化变得简单而强大!**
|
1108
|
+
|
1109
|
+
|
1110
|
+
## 🤝 贡献与支持
|
1111
|
+
|
1112
|
+
我们欢迎您的贡献和反馈!
|
1113
|
+
|
1114
|
+
- 🐛 [报告问题](https://github.com/felix-1991/pytest-dsl/issues)
|
1115
|
+
- 💡 [功能建议](https://github.com/felix-1991/pytest-dsl/discussions)
|
1116
|
+
- 🔧 [提交PR](https://github.com/felix-1991/pytest-dsl/pulls)
|
1117
|
+
|
1118
|
+
## 📄 许可证
|
1119
|
+
|
1120
|
+
MIT License - 详见 [LICENSE](LICENSE) 文件
|
1121
|
+
|
1122
|
+
---
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
4
4
|
|
5
5
|
[project]
|
6
6
|
name = "pytest-dsl"
|
7
|
-
version = "0.
|
7
|
+
version = "0.11.0"
|
8
8
|
description = "A DSL testing framework based on pytest"
|
9
9
|
readme = "README.md"
|
10
10
|
requires-python = ">=3.9"
|
@@ -33,6 +33,7 @@ dependencies = [
|
|
33
33
|
"lxml>=4.9.0",
|
34
34
|
"jsonschema>=4.17.0",
|
35
35
|
"pytz>=2023.3",
|
36
|
+
"Jinja2>=3.0.0",
|
36
37
|
]
|
37
38
|
|
38
39
|
[project.entry-points.pytest11]
|