pytest-dsl 0.3.1__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.
Files changed (77) hide show
  1. {pytest_dsl-0.3.1/pytest_dsl.egg-info → pytest_dsl-0.5.0}/PKG-INFO +159 -11
  2. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0}/README.md +155 -8
  3. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0}/pyproject.toml +6 -4
  4. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0}/pytest_dsl/core/dsl_executor.py +161 -48
  5. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0}/pytest_dsl/core/lexer.py +12 -1
  6. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0}/pytest_dsl/core/parser.py +25 -6
  7. pytest_dsl-0.5.0/pytest_dsl/core/parsetab.py +114 -0
  8. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0}/pytest_dsl/keywords/http_keywords.py +89 -89
  9. pytest_dsl-0.5.0/pytest_dsl/keywords/system_keywords.py +343 -0
  10. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0/pytest_dsl.egg-info}/PKG-INFO +159 -11
  11. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0}/pytest_dsl.egg-info/entry_points.txt +1 -0
  12. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0}/pytest_dsl.egg-info/requires.txt +1 -0
  13. pytest_dsl-0.3.1/pytest_dsl/core/parsetab.py +0 -109
  14. pytest_dsl-0.3.1/pytest_dsl/keywords/system_keywords.py +0 -17
  15. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0}/LICENSE +0 -0
  16. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0}/MANIFEST.in +0 -0
  17. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0}/pytest_dsl/__init__.py +0 -0
  18. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0}/pytest_dsl/cli.py +0 -0
  19. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0}/pytest_dsl/conftest_adapter.py +0 -0
  20. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0}/pytest_dsl/core/__init__.py +0 -0
  21. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0}/pytest_dsl/core/auth_provider.py +0 -0
  22. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0}/pytest_dsl/core/auto_decorator.py +0 -0
  23. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0}/pytest_dsl/core/auto_directory.py +0 -0
  24. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0}/pytest_dsl/core/context.py +0 -0
  25. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0}/pytest_dsl/core/custom_keyword_manager.py +0 -0
  26. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0}/pytest_dsl/core/dsl_executor_utils.py +0 -0
  27. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0}/pytest_dsl/core/global_context.py +0 -0
  28. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0}/pytest_dsl/core/http_client.py +0 -0
  29. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0}/pytest_dsl/core/http_request.py +0 -0
  30. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0}/pytest_dsl/core/keyword_manager.py +0 -0
  31. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0}/pytest_dsl/core/plugin_discovery.py +0 -0
  32. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0}/pytest_dsl/core/utils.py +0 -0
  33. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0}/pytest_dsl/core/variable_utils.py +0 -0
  34. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0}/pytest_dsl/core/yaml_loader.py +0 -0
  35. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0}/pytest_dsl/core/yaml_vars.py +0 -0
  36. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0}/pytest_dsl/docs/custom_keywords.md +0 -0
  37. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0}/pytest_dsl/examples/__init__.py +0 -0
  38. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0}/pytest_dsl/examples/assert/assertion_example.auto +0 -0
  39. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0}/pytest_dsl/examples/assert/boolean_test.auto +0 -0
  40. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0}/pytest_dsl/examples/assert/expression_test.auto +0 -0
  41. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0}/pytest_dsl/examples/custom/test_advanced_keywords.auto +0 -0
  42. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0}/pytest_dsl/examples/custom/test_custom_keywords.auto +0 -0
  43. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0}/pytest_dsl/examples/custom/test_default_values.auto +0 -0
  44. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0}/pytest_dsl/examples/http/__init__.py +0 -0
  45. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0}/pytest_dsl/examples/http/builtin_auth_test.auto +0 -0
  46. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0}/pytest_dsl/examples/http/file_reference_test.auto +0 -0
  47. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0}/pytest_dsl/examples/http/http_advanced.auto +0 -0
  48. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0}/pytest_dsl/examples/http/http_example.auto +0 -0
  49. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0}/pytest_dsl/examples/http/http_length_test.auto +0 -0
  50. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0}/pytest_dsl/examples/http/http_retry_assertions.auto +0 -0
  51. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0}/pytest_dsl/examples/http/http_retry_assertions_enhanced.auto +0 -0
  52. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0}/pytest_dsl/examples/http/http_with_yaml.auto +0 -0
  53. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0}/pytest_dsl/examples/http/new_retry_test.auto +0 -0
  54. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0}/pytest_dsl/examples/http/retry_assertions_only.auto +0 -0
  55. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0}/pytest_dsl/examples/http/retry_config_only.auto +0 -0
  56. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0}/pytest_dsl/examples/http/retry_debug.auto +0 -0
  57. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0}/pytest_dsl/examples/http/retry_with_fix.auto +0 -0
  58. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0}/pytest_dsl/examples/http/simple_retry.auto +0 -0
  59. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0}/pytest_dsl/examples/http/vars.yaml +0 -0
  60. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0}/pytest_dsl/examples/quickstart/api_basics.auto +0 -0
  61. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0}/pytest_dsl/examples/quickstart/assertions.auto +0 -0
  62. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0}/pytest_dsl/examples/quickstart/loops.auto +0 -0
  63. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0}/pytest_dsl/examples/test_assert.py +0 -0
  64. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0}/pytest_dsl/examples/test_custom_keyword.py +0 -0
  65. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0}/pytest_dsl/examples/test_http.py +0 -0
  66. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0}/pytest_dsl/examples/test_quickstart.py +0 -0
  67. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0}/pytest_dsl/keywords/__init__.py +0 -0
  68. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0}/pytest_dsl/keywords/assertion_keywords.py +0 -0
  69. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0}/pytest_dsl/keywords/global_keywords.py +0 -0
  70. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0}/pytest_dsl/main_adapter.py +0 -0
  71. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0}/pytest_dsl/parsetab.py +0 -0
  72. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0}/pytest_dsl/plugin.py +0 -0
  73. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0}/pytest_dsl.egg-info/SOURCES.txt +0 -0
  74. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0}/pytest_dsl.egg-info/dependency_links.txt +0 -0
  75. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0}/pytest_dsl.egg-info/top_level.txt +0 -0
  76. {pytest_dsl-0.3.1 → pytest_dsl-0.5.0}/setup.cfg +0 -0
  77. {pytest_dsl-0.3.1 → 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.1
3
+ Version: 0.5.0
4
4
  Summary: A DSL testing framework based on pytest
5
5
  Author: Chen Shuanglin
6
6
  License: MIT
@@ -8,13 +8,13 @@ Project-URL: Homepage, https://github.com/felix-1991/pytest-dsl
8
8
  Project-URL: Bug Tracker, https://github.com/felix-1991/pytest-dsl/issues
9
9
  Classifier: Framework :: Pytest
10
10
  Classifier: Programming Language :: Python :: 3
11
- Classifier: Programming Language :: Python :: 3.8
12
11
  Classifier: Programming Language :: Python :: 3.9
13
12
  Classifier: Programming Language :: Python :: 3.10
14
13
  Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
15
  Classifier: License :: OSI Approved :: MIT License
16
16
  Classifier: Operating System :: OS Independent
17
- Requires-Python: >=3.8
17
+ Requires-Python: >=3.9
18
18
  Description-Content-Type: text/markdown
19
19
  License-File: LICENSE
20
20
  Requires-Dist: pytest>=7.0.0
@@ -26,6 +26,7 @@ Requires-Dist: jsonpath-ng>=1.5.0
26
26
  Requires-Dist: requests>=2.28.0
27
27
  Requires-Dist: lxml>=4.9.0
28
28
  Requires-Dist: jsonschema>=4.17.0
29
+ Requires-Dist: pytz>=2023.3
29
30
  Dynamic: license-file
30
31
 
31
32
  # pytest-dsl: 强大的关键字驱动测试自动化框架
@@ -149,11 +150,11 @@ pytest-dsl允许在DSL文件中直接定义自定义关键字,类似于编程
149
150
  @keyword 拼接字符串 (前缀, 后缀="默认后缀") do
150
151
  # 直接使用关键字参数
151
152
  [打印],内容: "拼接前缀: ${前缀} 和后缀: ${后缀}"
152
-
153
+
153
154
  # 保存到变量中
154
155
  结果变量 = "${前缀}${后缀}"
155
156
  [打印],内容: "拼接结果: ${结果变量}"
156
-
157
+
157
158
  # 返回结果
158
159
  return ${结果变量}
159
160
  end
@@ -188,11 +189,11 @@ end
188
189
  @keyword 拼接字符串 (前缀, 后缀="我是默认值哦") do
189
190
  # 直接使用关键字参数
190
191
  [打印],内容:'拼接前缀: ${前缀} 和后缀: ${后缀}'
191
-
192
+
192
193
  # 保存到变量中
193
194
  结果变量 = "${前缀}${后缀}"
194
195
  [打印],内容:'拼接结果: ${结果变量}'
195
-
196
+
196
197
  # 返回结果
197
198
  return ${结果变量}
198
199
  end
@@ -311,7 +312,7 @@ from pytest_dsl.core.auto_decorator import auto_dsl
311
312
  @auto_dsl("./api_tests") # 加载指定目录下所有的.auto或.dsl文件
312
313
  class TestAPI:
313
314
  """API测试类
314
-
315
+
315
316
  该类将自动加载api_tests目录下的所有DSL文件作为测试方法
316
317
  """
317
318
  pass
@@ -330,6 +331,31 @@ pytest test_api.py
330
331
  pytest -v --alluredir=./reports
331
332
  ```
332
333
 
334
+ ### 使用Allure生成和查看报告
335
+
336
+ pytest-dsl已与Allure报告框架集成,可以生成美观、交互式的测试报告。
337
+
338
+ ```bash
339
+ # 运行测试并生成Allure报告数据
340
+ pytest --alluredir=./allure-results
341
+
342
+ # 生成HTML报告并启动本地服务器查看
343
+ allure serve ./allure-results
344
+
345
+ # 或生成HTML报告到指定目录
346
+ allure generate ./allure-results -o ./allure-report
347
+ # 然后可以打开 ./allure-report/index.html 查看报告
348
+ ```
349
+
350
+ Allure报告会自动包含以下信息:
351
+ - 测试步骤和执行状态
352
+ - HTTP请求和响应详情
353
+ - 断言结果和失败原因
354
+ - 测试执行时间和性能数据
355
+ - 测试标签和分类信息
356
+
357
+ 通过Allure报告,您可以更直观地分析测试结果,快速定位问题。
358
+
333
359
  ## 更多功能
334
360
 
335
361
  ### 断言重试功能
@@ -386,7 +412,7 @@ def call_microservice(**kwargs):
386
412
  method = kwargs.get('method_name')
387
413
  params = kwargs.get('params', {})
388
414
  context = kwargs.get('context')
389
-
415
+
390
416
  # 实现微服务调用逻辑
391
417
  result = your_microservice_client.call(service, method, params)
392
418
  return result
@@ -427,13 +453,135 @@ def call_microservice(**kwargs):
427
453
  - **完整测试生命周期**:内置teardown、变量管理和断言机制
428
454
  - **非侵入式设计**:以"旁路模式"扩展现有pytest项目,不影响原有测试代码
429
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
+
430
577
  ## 进阶文档
431
578
 
432
579
  - [完整DSL语法指南](./docs/自动化关键字DSL语法设计.md)
433
- - [创建自定义关键字](./pytest_dsl/docs/custom_keywords.md)
580
+ - [创建自定义关键字](./pytest_dsl/docs/custom_keywords.md)
434
581
  - [HTTP测试关键字](./docs/api.md)
435
582
  - [断言关键字详解](./docs/assertion_keywords.md)
436
583
  - [HTTP断言重试机制](./docs/http_assertion_retry.md)
584
+ - [远程关键字语法示例](./docs/remote_syntax_example.md)
437
585
 
438
586
  ## 贡献与支持
439
587
 
@@ -445,4 +593,4 @@ MIT License
445
593
 
446
594
  ---
447
595
 
448
- 开始使用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
@@ -300,6 +300,31 @@ pytest test_api.py
300
300
  pytest -v --alluredir=./reports
301
301
  ```
302
302
 
303
+ ### 使用Allure生成和查看报告
304
+
305
+ pytest-dsl已与Allure报告框架集成,可以生成美观、交互式的测试报告。
306
+
307
+ ```bash
308
+ # 运行测试并生成Allure报告数据
309
+ pytest --alluredir=./allure-results
310
+
311
+ # 生成HTML报告并启动本地服务器查看
312
+ allure serve ./allure-results
313
+
314
+ # 或生成HTML报告到指定目录
315
+ allure generate ./allure-results -o ./allure-report
316
+ # 然后可以打开 ./allure-report/index.html 查看报告
317
+ ```
318
+
319
+ Allure报告会自动包含以下信息:
320
+ - 测试步骤和执行状态
321
+ - HTTP请求和响应详情
322
+ - 断言结果和失败原因
323
+ - 测试执行时间和性能数据
324
+ - 测试标签和分类信息
325
+
326
+ 通过Allure报告,您可以更直观地分析测试结果,快速定位问题。
327
+
303
328
  ## 更多功能
304
329
 
305
330
  ### 断言重试功能
@@ -356,7 +381,7 @@ def call_microservice(**kwargs):
356
381
  method = kwargs.get('method_name')
357
382
  params = kwargs.get('params', {})
358
383
  context = kwargs.get('context')
359
-
384
+
360
385
  # 实现微服务调用逻辑
361
386
  result = your_microservice_client.call(service, method, params)
362
387
  return result
@@ -397,13 +422,135 @@ def call_microservice(**kwargs):
397
422
  - **完整测试生命周期**:内置teardown、变量管理和断言机制
398
423
  - **非侵入式设计**:以"旁路模式"扩展现有pytest项目,不影响原有测试代码
399
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
+
400
546
  ## 进阶文档
401
547
 
402
548
  - [完整DSL语法指南](./docs/自动化关键字DSL语法设计.md)
403
- - [创建自定义关键字](./pytest_dsl/docs/custom_keywords.md)
549
+ - [创建自定义关键字](./pytest_dsl/docs/custom_keywords.md)
404
550
  - [HTTP测试关键字](./docs/api.md)
405
551
  - [断言关键字详解](./docs/assertion_keywords.md)
406
552
  - [HTTP断言重试机制](./docs/http_assertion_retry.md)
553
+ - [远程关键字语法示例](./docs/remote_syntax_example.md)
407
554
 
408
555
  ## 贡献与支持
409
556
 
@@ -415,4 +562,4 @@ MIT License
415
562
 
416
563
  ---
417
564
 
418
- 开始使用pytest-dsl,释放测试自动化的无限可能!
565
+ 开始使用pytest-dsl,释放测试自动化的无限可能!
@@ -4,10 +4,10 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "pytest-dsl"
7
- version = "0.3.1"
7
+ version = "0.5.0"
8
8
  description = "A DSL testing framework based on pytest"
9
9
  readme = "README.md"
10
- requires-python = ">=3.8"
10
+ requires-python = ">=3.9"
11
11
  license = {text = "MIT"}
12
12
  authors = [
13
13
  {name = "Chen Shuanglin"}
@@ -15,10 +15,10 @@ authors = [
15
15
  classifiers = [
16
16
  "Framework :: Pytest",
17
17
  "Programming Language :: Python :: 3",
18
- "Programming Language :: Python :: 3.8",
19
18
  "Programming Language :: Python :: 3.9",
20
19
  "Programming Language :: Python :: 3.10",
21
20
  "Programming Language :: Python :: 3.11",
21
+ "Programming Language :: Python :: 3.12",
22
22
  "License :: OSI Approved :: MIT License",
23
23
  "Operating System :: OS Independent",
24
24
  ]
@@ -32,6 +32,7 @@ dependencies = [
32
32
  "requests>=2.28.0",
33
33
  "lxml>=4.9.0",
34
34
  "jsonschema>=4.17.0",
35
+ "pytz>=2023.3",
35
36
  ]
36
37
 
37
38
  [project.entry-points.pytest11]
@@ -39,7 +40,8 @@ pytest_dsl = "pytest_dsl.plugin"
39
40
 
40
41
  [project.scripts]
41
42
  pytest-dsl = "pytest_dsl.cli:main"
43
+ pytest-dsl-server = "pytest_dsl.remote.keyword_server:main"
42
44
 
43
45
  [project.urls]
44
46
  "Homepage" = "https://github.com/felix-1991/pytest-dsl"
45
- "Bug Tracker" = "https://github.com/felix-1991/pytest-dsl/issues"
47
+ "Bug Tracker" = "https://github.com/felix-1991/pytest-dsl/issues"