pytest-dsl 0.4.0__tar.gz → 0.5.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.4.0/pytest_dsl.egg-info → pytest_dsl-0.5.0}/PKG-INFO +131 -9
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/README.md +130 -8
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/pyproject.toml +2 -1
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/pytest_dsl/core/dsl_executor.py +161 -48
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/pytest_dsl/core/lexer.py +12 -1
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/pytest_dsl/core/parser.py +25 -6
- pytest_dsl-0.5.0/pytest_dsl/core/parsetab.py +114 -0
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/pytest_dsl/keywords/http_keywords.py +89 -89
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0/pytest_dsl.egg-info}/PKG-INFO +131 -9
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/pytest_dsl.egg-info/entry_points.txt +1 -0
- pytest_dsl-0.4.0/pytest_dsl/core/parsetab.py +0 -109
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/LICENSE +0 -0
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/MANIFEST.in +0 -0
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/pytest_dsl/__init__.py +0 -0
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/pytest_dsl/cli.py +0 -0
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/pytest_dsl/conftest_adapter.py +0 -0
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/pytest_dsl/core/__init__.py +0 -0
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/pytest_dsl/core/auth_provider.py +0 -0
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/pytest_dsl/core/auto_decorator.py +0 -0
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/pytest_dsl/core/auto_directory.py +0 -0
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/pytest_dsl/core/context.py +0 -0
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/pytest_dsl/core/custom_keyword_manager.py +0 -0
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/pytest_dsl/core/dsl_executor_utils.py +0 -0
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/pytest_dsl/core/global_context.py +0 -0
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/pytest_dsl/core/http_client.py +0 -0
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/pytest_dsl/core/http_request.py +0 -0
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/pytest_dsl/core/keyword_manager.py +0 -0
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/pytest_dsl/core/plugin_discovery.py +0 -0
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/pytest_dsl/core/utils.py +0 -0
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/pytest_dsl/core/variable_utils.py +0 -0
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/pytest_dsl/core/yaml_loader.py +0 -0
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/pytest_dsl/core/yaml_vars.py +0 -0
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/pytest_dsl/docs/custom_keywords.md +0 -0
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/pytest_dsl/examples/__init__.py +0 -0
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/pytest_dsl/examples/assert/assertion_example.auto +0 -0
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/pytest_dsl/examples/assert/boolean_test.auto +0 -0
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/pytest_dsl/examples/assert/expression_test.auto +0 -0
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/pytest_dsl/examples/custom/test_advanced_keywords.auto +0 -0
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/pytest_dsl/examples/custom/test_custom_keywords.auto +0 -0
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/pytest_dsl/examples/custom/test_default_values.auto +0 -0
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/pytest_dsl/examples/http/__init__.py +0 -0
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/pytest_dsl/examples/http/builtin_auth_test.auto +0 -0
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/pytest_dsl/examples/http/file_reference_test.auto +0 -0
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/pytest_dsl/examples/http/http_advanced.auto +0 -0
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/pytest_dsl/examples/http/http_example.auto +0 -0
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/pytest_dsl/examples/http/http_length_test.auto +0 -0
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/pytest_dsl/examples/http/http_retry_assertions.auto +0 -0
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/pytest_dsl/examples/http/http_retry_assertions_enhanced.auto +0 -0
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/pytest_dsl/examples/http/http_with_yaml.auto +0 -0
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/pytest_dsl/examples/http/new_retry_test.auto +0 -0
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/pytest_dsl/examples/http/retry_assertions_only.auto +0 -0
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/pytest_dsl/examples/http/retry_config_only.auto +0 -0
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/pytest_dsl/examples/http/retry_debug.auto +0 -0
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/pytest_dsl/examples/http/retry_with_fix.auto +0 -0
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/pytest_dsl/examples/http/simple_retry.auto +0 -0
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/pytest_dsl/examples/http/vars.yaml +0 -0
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/pytest_dsl/examples/quickstart/api_basics.auto +0 -0
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/pytest_dsl/examples/quickstart/assertions.auto +0 -0
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/pytest_dsl/examples/quickstart/loops.auto +0 -0
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/pytest_dsl/examples/test_assert.py +0 -0
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/pytest_dsl/examples/test_custom_keyword.py +0 -0
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/pytest_dsl/examples/test_http.py +0 -0
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/pytest_dsl/examples/test_quickstart.py +0 -0
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/pytest_dsl/keywords/__init__.py +0 -0
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/pytest_dsl/keywords/assertion_keywords.py +0 -0
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/pytest_dsl/keywords/global_keywords.py +0 -0
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/pytest_dsl/keywords/system_keywords.py +0 -0
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/pytest_dsl/main_adapter.py +0 -0
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/pytest_dsl/parsetab.py +0 -0
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/pytest_dsl/plugin.py +0 -0
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/pytest_dsl.egg-info/SOURCES.txt +0 -0
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/pytest_dsl.egg-info/dependency_links.txt +0 -0
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/pytest_dsl.egg-info/requires.txt +0 -0
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/pytest_dsl.egg-info/top_level.txt +0 -0
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/setup.cfg +0 -0
- {pytest_dsl-0.4.0 → pytest_dsl-0.5.0}/setup.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: pytest-dsl
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.5.0
|
4
4
|
Summary: A DSL testing framework based on pytest
|
5
5
|
Author: Chen Shuanglin
|
6
6
|
License: MIT
|
@@ -150,11 +150,11 @@ pytest-dsl允许在DSL文件中直接定义自定义关键字,类似于编程
|
|
150
150
|
@keyword 拼接字符串 (前缀, 后缀="默认后缀") do
|
151
151
|
# 直接使用关键字参数
|
152
152
|
[打印],内容: "拼接前缀: ${前缀} 和后缀: ${后缀}"
|
153
|
-
|
153
|
+
|
154
154
|
# 保存到变量中
|
155
155
|
结果变量 = "${前缀}${后缀}"
|
156
156
|
[打印],内容: "拼接结果: ${结果变量}"
|
157
|
-
|
157
|
+
|
158
158
|
# 返回结果
|
159
159
|
return ${结果变量}
|
160
160
|
end
|
@@ -189,11 +189,11 @@ end
|
|
189
189
|
@keyword 拼接字符串 (前缀, 后缀="我是默认值哦") do
|
190
190
|
# 直接使用关键字参数
|
191
191
|
[打印],内容:'拼接前缀: ${前缀} 和后缀: ${后缀}'
|
192
|
-
|
192
|
+
|
193
193
|
# 保存到变量中
|
194
194
|
结果变量 = "${前缀}${后缀}"
|
195
195
|
[打印],内容:'拼接结果: ${结果变量}'
|
196
|
-
|
196
|
+
|
197
197
|
# 返回结果
|
198
198
|
return ${结果变量}
|
199
199
|
end
|
@@ -312,7 +312,7 @@ from pytest_dsl.core.auto_decorator import auto_dsl
|
|
312
312
|
@auto_dsl("./api_tests") # 加载指定目录下所有的.auto或.dsl文件
|
313
313
|
class TestAPI:
|
314
314
|
"""API测试类
|
315
|
-
|
315
|
+
|
316
316
|
该类将自动加载api_tests目录下的所有DSL文件作为测试方法
|
317
317
|
"""
|
318
318
|
pass
|
@@ -412,7 +412,7 @@ def call_microservice(**kwargs):
|
|
412
412
|
method = kwargs.get('method_name')
|
413
413
|
params = kwargs.get('params', {})
|
414
414
|
context = kwargs.get('context')
|
415
|
-
|
415
|
+
|
416
416
|
# 实现微服务调用逻辑
|
417
417
|
result = your_microservice_client.call(service, method, params)
|
418
418
|
return result
|
@@ -453,13 +453,135 @@ def call_microservice(**kwargs):
|
|
453
453
|
- **完整测试生命周期**:内置teardown、变量管理和断言机制
|
454
454
|
- **非侵入式设计**:以"旁路模式"扩展现有pytest项目,不影响原有测试代码
|
455
455
|
|
456
|
+
## 远程关键字功能
|
457
|
+
|
458
|
+
pytest-dsl支持远程关键字调用,允许您在不同的机器或服务上执行关键字,实现分布式测试。
|
459
|
+
|
460
|
+
### 启动远程关键字服务
|
461
|
+
|
462
|
+
安装pytest-dsl后,可以使用内置命令启动远程关键字服务:
|
463
|
+
|
464
|
+
```bash
|
465
|
+
# 使用默认配置启动(localhost:8270)
|
466
|
+
pytest-dsl-server
|
467
|
+
|
468
|
+
# 自定义主机和端口
|
469
|
+
pytest-dsl-server --host 0.0.0.0 --port 8888
|
470
|
+
|
471
|
+
# 使用API密钥保护服务
|
472
|
+
pytest-dsl-server --api-key your_secret_key
|
473
|
+
```
|
474
|
+
|
475
|
+
#### 分布式测试环境配置
|
476
|
+
|
477
|
+
在分布式测试环境中,您可以在多台机器上启动远程关键字服务:
|
478
|
+
|
479
|
+
1. **主测试机**:运行测试脚本的机器
|
480
|
+
2. **远程执行机**:运行远程关键字服务的机器
|
481
|
+
|
482
|
+
配置步骤:
|
483
|
+
|
484
|
+
1. 在每台远程执行机上安装pytest-dsl:
|
485
|
+
```bash
|
486
|
+
pip install pytest-dsl
|
487
|
+
```
|
488
|
+
|
489
|
+
2. 在每台远程执行机上启动远程关键字服务:
|
490
|
+
```bash
|
491
|
+
# 确保监听所有网络接口,以便外部可访问
|
492
|
+
pytest-dsl-server --host 0.0.0.0 --port 8270
|
493
|
+
```
|
494
|
+
|
495
|
+
3. 在主测试机上编写测试脚本,使用`@remote`指令连接到远程服务:
|
496
|
+
```python
|
497
|
+
# 连接到多台远程执行机
|
498
|
+
@remote: "http://machine1-ip:8270/" as machine1
|
499
|
+
@remote: "http://machine2-ip:8270/" as machine2
|
500
|
+
|
501
|
+
# 在不同机器上执行关键字
|
502
|
+
machine1|[打印],内容: "在机器1上执行"
|
503
|
+
machine2|[打印],内容: "在机器2上执行"
|
504
|
+
```
|
505
|
+
|
506
|
+
### 远程关键字语法
|
507
|
+
|
508
|
+
```python
|
509
|
+
# 导入远程关键字服务器
|
510
|
+
@remote: "http://keyword-server:8270/" as machineone
|
511
|
+
@remote: "http://keyword-server2:8270/" as machinetwo
|
512
|
+
|
513
|
+
# 远程关键字调用
|
514
|
+
machineone|[打印],内容: "这是通过远程服务器执行的关键字"
|
515
|
+
结果 = machineone|[拼接字符串],前缀: "Hello, ",后缀: "Remote World!"
|
516
|
+
```
|
517
|
+
|
518
|
+
### 远程关键字测试示例
|
519
|
+
|
520
|
+
```python
|
521
|
+
@name: "远程关键字测试"
|
522
|
+
@description: "测试远程关键字的基本功能"
|
523
|
+
@tags: ["remote", "keywords"]
|
524
|
+
@author: "Felix"
|
525
|
+
@date: 2024-05-21
|
526
|
+
|
527
|
+
# 导入远程关键字服务器
|
528
|
+
@remote: "http://localhost:8270/" as machineone
|
529
|
+
|
530
|
+
# 基本打印测试
|
531
|
+
machineone|[打印],内容: "这是通过远程服务器执行的关键字"
|
532
|
+
|
533
|
+
# 随机数生成测试
|
534
|
+
随机数 = [生成随机数],最小值: 1,最大值: 100
|
535
|
+
machineone|[打印],内容: "远程生成的随机数: ${随机数}"
|
536
|
+
```
|
537
|
+
|
538
|
+
> **注意**:当前远程关键字模式在HTTP请求关键字上支持的不是太好,后续会优化关键字实现,提升远程关键字的功能和稳定性。
|
539
|
+
|
540
|
+
### 远程关键字服务安全性
|
541
|
+
|
542
|
+
在生产环境中使用远程关键字服务时,请注意以下安全建议:
|
543
|
+
|
544
|
+
1. **使用API密钥认证**:
|
545
|
+
```bash
|
546
|
+
pytest-dsl-server --api-key your_secure_key
|
547
|
+
```
|
548
|
+
然后在测试脚本中使用API密钥连接:
|
549
|
+
```python
|
550
|
+
@remote: "http://server:8270/?api_key=your_secure_key" as secure_server
|
551
|
+
```
|
552
|
+
|
553
|
+
2. **限制网络访问**:
|
554
|
+
- 在内部网络或VPN中使用远程关键字服务
|
555
|
+
- 使用防火墙限制对服务端口的访问
|
556
|
+
- 考虑使用SSH隧道连接到远程服务
|
557
|
+
|
558
|
+
3. **监控服务**:
|
559
|
+
- 定期检查服务日志
|
560
|
+
- 监控异常访问模式
|
561
|
+
- 在不需要时关闭服务
|
562
|
+
|
563
|
+
### 远程关键字最佳实践
|
564
|
+
|
565
|
+
1. **合理分配关键字**:
|
566
|
+
- 将计算密集型关键字放在性能更好的机器上
|
567
|
+
- 将特定环境依赖的关键字放在对应环境的机器上
|
568
|
+
|
569
|
+
2. **错误处理**:
|
570
|
+
- 添加适当的错误处理机制,处理远程服务不可用的情况
|
571
|
+
- 使用超时设置避免长时间等待
|
572
|
+
|
573
|
+
3. **变量传递**:
|
574
|
+
- 注意远程关键字执行后,变量会返回到本地上下文
|
575
|
+
- 大型数据应考虑使用文件或数据库共享,而不是直接通过变量传递
|
576
|
+
|
456
577
|
## 进阶文档
|
457
578
|
|
458
579
|
- [完整DSL语法指南](./docs/自动化关键字DSL语法设计.md)
|
459
|
-
- [创建自定义关键字](./pytest_dsl/docs/custom_keywords.md)
|
580
|
+
- [创建自定义关键字](./pytest_dsl/docs/custom_keywords.md)
|
460
581
|
- [HTTP测试关键字](./docs/api.md)
|
461
582
|
- [断言关键字详解](./docs/assertion_keywords.md)
|
462
583
|
- [HTTP断言重试机制](./docs/http_assertion_retry.md)
|
584
|
+
- [远程关键字语法示例](./docs/remote_syntax_example.md)
|
463
585
|
|
464
586
|
## 贡献与支持
|
465
587
|
|
@@ -471,4 +593,4 @@ MIT License
|
|
471
593
|
|
472
594
|
---
|
473
595
|
|
474
|
-
开始使用pytest-dsl,释放测试自动化的无限可能!
|
596
|
+
开始使用pytest-dsl,释放测试自动化的无限可能!
|
@@ -119,11 +119,11 @@ pytest-dsl允许在DSL文件中直接定义自定义关键字,类似于编程
|
|
119
119
|
@keyword 拼接字符串 (前缀, 后缀="默认后缀") do
|
120
120
|
# 直接使用关键字参数
|
121
121
|
[打印],内容: "拼接前缀: ${前缀} 和后缀: ${后缀}"
|
122
|
-
|
122
|
+
|
123
123
|
# 保存到变量中
|
124
124
|
结果变量 = "${前缀}${后缀}"
|
125
125
|
[打印],内容: "拼接结果: ${结果变量}"
|
126
|
-
|
126
|
+
|
127
127
|
# 返回结果
|
128
128
|
return ${结果变量}
|
129
129
|
end
|
@@ -158,11 +158,11 @@ end
|
|
158
158
|
@keyword 拼接字符串 (前缀, 后缀="我是默认值哦") do
|
159
159
|
# 直接使用关键字参数
|
160
160
|
[打印],内容:'拼接前缀: ${前缀} 和后缀: ${后缀}'
|
161
|
-
|
161
|
+
|
162
162
|
# 保存到变量中
|
163
163
|
结果变量 = "${前缀}${后缀}"
|
164
164
|
[打印],内容:'拼接结果: ${结果变量}'
|
165
|
-
|
165
|
+
|
166
166
|
# 返回结果
|
167
167
|
return ${结果变量}
|
168
168
|
end
|
@@ -281,7 +281,7 @@ from pytest_dsl.core.auto_decorator import auto_dsl
|
|
281
281
|
@auto_dsl("./api_tests") # 加载指定目录下所有的.auto或.dsl文件
|
282
282
|
class TestAPI:
|
283
283
|
"""API测试类
|
284
|
-
|
284
|
+
|
285
285
|
该类将自动加载api_tests目录下的所有DSL文件作为测试方法
|
286
286
|
"""
|
287
287
|
pass
|
@@ -381,7 +381,7 @@ def call_microservice(**kwargs):
|
|
381
381
|
method = kwargs.get('method_name')
|
382
382
|
params = kwargs.get('params', {})
|
383
383
|
context = kwargs.get('context')
|
384
|
-
|
384
|
+
|
385
385
|
# 实现微服务调用逻辑
|
386
386
|
result = your_microservice_client.call(service, method, params)
|
387
387
|
return result
|
@@ -422,13 +422,135 @@ def call_microservice(**kwargs):
|
|
422
422
|
- **完整测试生命周期**:内置teardown、变量管理和断言机制
|
423
423
|
- **非侵入式设计**:以"旁路模式"扩展现有pytest项目,不影响原有测试代码
|
424
424
|
|
425
|
+
## 远程关键字功能
|
426
|
+
|
427
|
+
pytest-dsl支持远程关键字调用,允许您在不同的机器或服务上执行关键字,实现分布式测试。
|
428
|
+
|
429
|
+
### 启动远程关键字服务
|
430
|
+
|
431
|
+
安装pytest-dsl后,可以使用内置命令启动远程关键字服务:
|
432
|
+
|
433
|
+
```bash
|
434
|
+
# 使用默认配置启动(localhost:8270)
|
435
|
+
pytest-dsl-server
|
436
|
+
|
437
|
+
# 自定义主机和端口
|
438
|
+
pytest-dsl-server --host 0.0.0.0 --port 8888
|
439
|
+
|
440
|
+
# 使用API密钥保护服务
|
441
|
+
pytest-dsl-server --api-key your_secret_key
|
442
|
+
```
|
443
|
+
|
444
|
+
#### 分布式测试环境配置
|
445
|
+
|
446
|
+
在分布式测试环境中,您可以在多台机器上启动远程关键字服务:
|
447
|
+
|
448
|
+
1. **主测试机**:运行测试脚本的机器
|
449
|
+
2. **远程执行机**:运行远程关键字服务的机器
|
450
|
+
|
451
|
+
配置步骤:
|
452
|
+
|
453
|
+
1. 在每台远程执行机上安装pytest-dsl:
|
454
|
+
```bash
|
455
|
+
pip install pytest-dsl
|
456
|
+
```
|
457
|
+
|
458
|
+
2. 在每台远程执行机上启动远程关键字服务:
|
459
|
+
```bash
|
460
|
+
# 确保监听所有网络接口,以便外部可访问
|
461
|
+
pytest-dsl-server --host 0.0.0.0 --port 8270
|
462
|
+
```
|
463
|
+
|
464
|
+
3. 在主测试机上编写测试脚本,使用`@remote`指令连接到远程服务:
|
465
|
+
```python
|
466
|
+
# 连接到多台远程执行机
|
467
|
+
@remote: "http://machine1-ip:8270/" as machine1
|
468
|
+
@remote: "http://machine2-ip:8270/" as machine2
|
469
|
+
|
470
|
+
# 在不同机器上执行关键字
|
471
|
+
machine1|[打印],内容: "在机器1上执行"
|
472
|
+
machine2|[打印],内容: "在机器2上执行"
|
473
|
+
```
|
474
|
+
|
475
|
+
### 远程关键字语法
|
476
|
+
|
477
|
+
```python
|
478
|
+
# 导入远程关键字服务器
|
479
|
+
@remote: "http://keyword-server:8270/" as machineone
|
480
|
+
@remote: "http://keyword-server2:8270/" as machinetwo
|
481
|
+
|
482
|
+
# 远程关键字调用
|
483
|
+
machineone|[打印],内容: "这是通过远程服务器执行的关键字"
|
484
|
+
结果 = machineone|[拼接字符串],前缀: "Hello, ",后缀: "Remote World!"
|
485
|
+
```
|
486
|
+
|
487
|
+
### 远程关键字测试示例
|
488
|
+
|
489
|
+
```python
|
490
|
+
@name: "远程关键字测试"
|
491
|
+
@description: "测试远程关键字的基本功能"
|
492
|
+
@tags: ["remote", "keywords"]
|
493
|
+
@author: "Felix"
|
494
|
+
@date: 2024-05-21
|
495
|
+
|
496
|
+
# 导入远程关键字服务器
|
497
|
+
@remote: "http://localhost:8270/" as machineone
|
498
|
+
|
499
|
+
# 基本打印测试
|
500
|
+
machineone|[打印],内容: "这是通过远程服务器执行的关键字"
|
501
|
+
|
502
|
+
# 随机数生成测试
|
503
|
+
随机数 = [生成随机数],最小值: 1,最大值: 100
|
504
|
+
machineone|[打印],内容: "远程生成的随机数: ${随机数}"
|
505
|
+
```
|
506
|
+
|
507
|
+
> **注意**:当前远程关键字模式在HTTP请求关键字上支持的不是太好,后续会优化关键字实现,提升远程关键字的功能和稳定性。
|
508
|
+
|
509
|
+
### 远程关键字服务安全性
|
510
|
+
|
511
|
+
在生产环境中使用远程关键字服务时,请注意以下安全建议:
|
512
|
+
|
513
|
+
1. **使用API密钥认证**:
|
514
|
+
```bash
|
515
|
+
pytest-dsl-server --api-key your_secure_key
|
516
|
+
```
|
517
|
+
然后在测试脚本中使用API密钥连接:
|
518
|
+
```python
|
519
|
+
@remote: "http://server:8270/?api_key=your_secure_key" as secure_server
|
520
|
+
```
|
521
|
+
|
522
|
+
2. **限制网络访问**:
|
523
|
+
- 在内部网络或VPN中使用远程关键字服务
|
524
|
+
- 使用防火墙限制对服务端口的访问
|
525
|
+
- 考虑使用SSH隧道连接到远程服务
|
526
|
+
|
527
|
+
3. **监控服务**:
|
528
|
+
- 定期检查服务日志
|
529
|
+
- 监控异常访问模式
|
530
|
+
- 在不需要时关闭服务
|
531
|
+
|
532
|
+
### 远程关键字最佳实践
|
533
|
+
|
534
|
+
1. **合理分配关键字**:
|
535
|
+
- 将计算密集型关键字放在性能更好的机器上
|
536
|
+
- 将特定环境依赖的关键字放在对应环境的机器上
|
537
|
+
|
538
|
+
2. **错误处理**:
|
539
|
+
- 添加适当的错误处理机制,处理远程服务不可用的情况
|
540
|
+
- 使用超时设置避免长时间等待
|
541
|
+
|
542
|
+
3. **变量传递**:
|
543
|
+
- 注意远程关键字执行后,变量会返回到本地上下文
|
544
|
+
- 大型数据应考虑使用文件或数据库共享,而不是直接通过变量传递
|
545
|
+
|
425
546
|
## 进阶文档
|
426
547
|
|
427
548
|
- [完整DSL语法指南](./docs/自动化关键字DSL语法设计.md)
|
428
|
-
- [创建自定义关键字](./pytest_dsl/docs/custom_keywords.md)
|
549
|
+
- [创建自定义关键字](./pytest_dsl/docs/custom_keywords.md)
|
429
550
|
- [HTTP测试关键字](./docs/api.md)
|
430
551
|
- [断言关键字详解](./docs/assertion_keywords.md)
|
431
552
|
- [HTTP断言重试机制](./docs/http_assertion_retry.md)
|
553
|
+
- [远程关键字语法示例](./docs/remote_syntax_example.md)
|
432
554
|
|
433
555
|
## 贡献与支持
|
434
556
|
|
@@ -440,4 +562,4 @@ MIT License
|
|
440
562
|
|
441
563
|
---
|
442
564
|
|
443
|
-
开始使用pytest-dsl,释放测试自动化的无限可能!
|
565
|
+
开始使用pytest-dsl,释放测试自动化的无限可能!
|
@@ -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.5.0"
|
8
8
|
description = "A DSL testing framework based on pytest"
|
9
9
|
readme = "README.md"
|
10
10
|
requires-python = ">=3.9"
|
@@ -40,6 +40,7 @@ pytest_dsl = "pytest_dsl.plugin"
|
|
40
40
|
|
41
41
|
[project.scripts]
|
42
42
|
pytest-dsl = "pytest_dsl.cli:main"
|
43
|
+
pytest-dsl-server = "pytest_dsl.remote.keyword_server:main"
|
43
44
|
|
44
45
|
[project.urls]
|
45
46
|
"Homepage" = "https://github.com/felix-1991/pytest-dsl"
|