pytest-dsl 0.11.1__py3-none-any.whl → 0.12.0__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.
@@ -185,7 +185,8 @@ def generate_random_number(**kwargs):
185
185
 
186
186
  @keyword_manager.register('字符串操作', [
187
187
  {'name': '操作', 'mapping': 'operation',
188
- 'description': '操作类型:拼接(concat)、替换(replace)、分割(split)、大写(upper)、小写(lower)、去空格(strip)',
188
+ 'description': '操作类型:拼接(concat)、替换(replace)、分割(split)'
189
+ '大写(upper)、小写(lower)、去空格(strip)',
189
190
  'default': 'strip'},
190
191
  {'name': '字符串', 'mapping': 'string', 'description': '要操作的字符串'},
191
192
  {'name': '参数1', 'mapping': 'param1',
@@ -366,3 +367,421 @@ def execute_command(**kwargs):
366
367
  'stdout': '',
367
368
  'stderr': str(e)
368
369
  }
370
+
371
+
372
+ @keyword_manager.register('求和', [
373
+ {'name': '数据', 'mapping': 'data', 'description': '要求和的数字列表或可迭代对象'},
374
+ {'name': '起始值', 'mapping': 'start', 'description': '求和的起始值', 'default': 0}
375
+ ])
376
+ def sum_values(**kwargs):
377
+ """计算数字列表的总和
378
+
379
+ Args:
380
+ data: 要求和的数字列表
381
+ start: 求和的起始值,默认为0
382
+
383
+ Returns:
384
+ 数字总和
385
+ """
386
+ data = kwargs.get('data', [])
387
+ start = kwargs.get('start', 0)
388
+
389
+ # 确保data是可迭代的
390
+ if not hasattr(data, '__iter__') or isinstance(data, str):
391
+ raise ValueError("数据必须是可迭代的数字列表")
392
+
393
+ try:
394
+ result = sum(data, start)
395
+
396
+ with allure.step(f"求和计算: 数据长度={len(data)}, 起始值={start}"):
397
+ allure.attach(
398
+ f"输入数据: {data}\n起始值: {start}\n结果: {result}",
399
+ name="求和结果",
400
+ attachment_type=allure.attachment_type.TEXT
401
+ )
402
+
403
+ return result
404
+ except Exception as e:
405
+ allure.attach(
406
+ f"求和计算失败: {str(e)}",
407
+ name="求和错误",
408
+ attachment_type=allure.attachment_type.TEXT
409
+ )
410
+ raise
411
+
412
+
413
+ @keyword_manager.register('获取长度', [
414
+ {'name': '对象', 'mapping': 'obj', 'description': '要获取长度的对象(字符串、列表、字典等)'}
415
+ ])
416
+ def get_length(**kwargs):
417
+ """获取对象的长度
418
+
419
+ Args:
420
+ obj: 要获取长度的对象
421
+
422
+ Returns:
423
+ int: 对象的长度
424
+ """
425
+ obj = kwargs.get('obj')
426
+
427
+ if obj is None:
428
+ return 0
429
+
430
+ try:
431
+ result = len(obj)
432
+
433
+ with allure.step(f"获取长度: 对象类型={type(obj).__name__}"):
434
+ allure.attach(
435
+ f"对象: {obj}\n类型: {type(obj).__name__}\n长度: {result}",
436
+ name="长度计算结果",
437
+ attachment_type=allure.attachment_type.TEXT
438
+ )
439
+
440
+ return result
441
+ except Exception as e:
442
+ allure.attach(
443
+ f"获取长度失败: {str(e)}",
444
+ name="长度计算错误",
445
+ attachment_type=allure.attachment_type.TEXT
446
+ )
447
+ raise
448
+
449
+
450
+ @keyword_manager.register('获取最大值', [
451
+ {'name': '数据', 'mapping': 'data', 'description': '要比较的数据列表或多个参数'},
452
+ {'name': '默认值', 'mapping': 'default',
453
+ 'description': '当数据为空时的默认值', 'default': None}
454
+ ])
455
+ def get_max_value(**kwargs):
456
+ """获取最大值
457
+
458
+ Args:
459
+ data: 要比较的数据
460
+ default: 当数据为空时的默认值
461
+
462
+ Returns:
463
+ 最大值
464
+ """
465
+ data = kwargs.get('data')
466
+ default = kwargs.get('default')
467
+
468
+ if data is None:
469
+ if default is not None:
470
+ return default
471
+ raise ValueError("数据不能为空")
472
+
473
+ try:
474
+ # 如果data不是可迭代的,将其转换为列表
475
+ if not hasattr(data, '__iter__') or isinstance(data, str):
476
+ data = [data]
477
+
478
+ if len(data) == 0:
479
+ if default is not None:
480
+ return default
481
+ raise ValueError("数据列表为空")
482
+
483
+ result = max(data)
484
+
485
+ with allure.step(f"获取最大值: 数据长度={len(data)}"):
486
+ allure.attach(
487
+ f"输入数据: {data}\n最大值: {result}",
488
+ name="最大值计算结果",
489
+ attachment_type=allure.attachment_type.TEXT
490
+ )
491
+
492
+ return result
493
+ except Exception as e:
494
+ allure.attach(
495
+ f"获取最大值失败: {str(e)}",
496
+ name="最大值计算错误",
497
+ attachment_type=allure.attachment_type.TEXT
498
+ )
499
+ raise
500
+
501
+
502
+ @keyword_manager.register('获取最小值', [
503
+ {'name': '数据', 'mapping': 'data', 'description': '要比较的数据列表或多个参数'},
504
+ {'name': '默认值', 'mapping': 'default',
505
+ 'description': '当数据为空时的默认值', 'default': None}
506
+ ])
507
+ def get_min_value(**kwargs):
508
+ """获取最小值
509
+
510
+ Args:
511
+ data: 要比较的数据
512
+ default: 当数据为空时的默认值
513
+
514
+ Returns:
515
+ 最小值
516
+ """
517
+ data = kwargs.get('data')
518
+ default = kwargs.get('default')
519
+
520
+ if data is None:
521
+ if default is not None:
522
+ return default
523
+ raise ValueError("数据不能为空")
524
+
525
+ try:
526
+ # 如果data不是可迭代的,将其转换为列表
527
+ if not hasattr(data, '__iter__') or isinstance(data, str):
528
+ data = [data]
529
+
530
+ if len(data) == 0:
531
+ if default is not None:
532
+ return default
533
+ raise ValueError("数据列表为空")
534
+
535
+ result = min(data)
536
+
537
+ with allure.step(f"获取最小值: 数据长度={len(data)}"):
538
+ allure.attach(
539
+ f"输入数据: {data}\n最小值: {result}",
540
+ name="最小值计算结果",
541
+ attachment_type=allure.attachment_type.TEXT
542
+ )
543
+
544
+ return result
545
+ except Exception as e:
546
+ allure.attach(
547
+ f"获取最小值失败: {str(e)}",
548
+ name="最小值计算错误",
549
+ attachment_type=allure.attachment_type.TEXT
550
+ )
551
+ raise
552
+
553
+
554
+ @keyword_manager.register('绝对值', [
555
+ {'name': '数值', 'mapping': 'number', 'description': '要计算绝对值的数字'}
556
+ ])
557
+ def get_absolute_value(**kwargs):
558
+ """计算数字的绝对值
559
+
560
+ Args:
561
+ number: 要计算绝对值的数字
562
+
563
+ Returns:
564
+ 数字的绝对值
565
+ """
566
+ number = kwargs.get('number')
567
+
568
+ if number is None:
569
+ raise ValueError("数值不能为空")
570
+
571
+ try:
572
+ result = abs(number)
573
+
574
+ with allure.step(f"计算绝对值: {number}"):
575
+ allure.attach(
576
+ f"输入数值: {number}\n绝对值: {result}",
577
+ name="绝对值计算结果",
578
+ attachment_type=allure.attachment_type.TEXT
579
+ )
580
+
581
+ return result
582
+ except Exception as e:
583
+ allure.attach(
584
+ f"计算绝对值失败: {str(e)}",
585
+ name="绝对值计算错误",
586
+ attachment_type=allure.attachment_type.TEXT
587
+ )
588
+ raise
589
+
590
+
591
+ @keyword_manager.register('四舍五入', [
592
+ {'name': '数值', 'mapping': 'number', 'description': '要四舍五入的数字'},
593
+ {'name': '小数位数', 'mapping': 'ndigits',
594
+ 'description': '保留的小数位数', 'default': 0}
595
+ ])
596
+ def round_number(**kwargs):
597
+ """对数字进行四舍五入
598
+
599
+ Args:
600
+ number: 要四舍五入的数字
601
+ ndigits: 保留的小数位数,默认为0(整数)
602
+
603
+ Returns:
604
+ 四舍五入后的数字
605
+ """
606
+ number = kwargs.get('number')
607
+ ndigits = kwargs.get('ndigits', 0)
608
+
609
+ if number is None:
610
+ raise ValueError("数值不能为空")
611
+
612
+ try:
613
+ if ndigits == 0:
614
+ result = round(number)
615
+ else:
616
+ result = round(number, int(ndigits))
617
+
618
+ with allure.step(f"四舍五入: {number} -> {ndigits}位小数"):
619
+ allure.attach(
620
+ f"输入数值: {number}\n小数位数: {ndigits}\n结果: {result}",
621
+ name="四舍五入结果",
622
+ attachment_type=allure.attachment_type.TEXT
623
+ )
624
+
625
+ return result
626
+ except Exception as e:
627
+ allure.attach(
628
+ f"四舍五入失败: {str(e)}",
629
+ name="四舍五入错误",
630
+ attachment_type=allure.attachment_type.TEXT
631
+ )
632
+ raise
633
+
634
+
635
+ @keyword_manager.register('转换为字符串', [
636
+ {'name': '值', 'mapping': 'value', 'description': '要转换为字符串的值'}
637
+ ])
638
+ def convert_to_string(**kwargs):
639
+ """将值转换为字符串
640
+
641
+ Args:
642
+ value: 要转换的值
643
+
644
+ Returns:
645
+ str: 转换后的字符串
646
+ """
647
+ value = kwargs.get('value')
648
+
649
+ try:
650
+ result = str(value)
651
+
652
+ with allure.step(f"转换为字符串: {type(value).__name__} -> str"):
653
+ allure.attach(
654
+ f"原始值: {value}\n原始类型: {type(value).__name__}\n"
655
+ f"转换结果: {result}\n结果类型: {type(result).__name__}",
656
+ name="字符串转换结果",
657
+ attachment_type=allure.attachment_type.TEXT
658
+ )
659
+
660
+ return result
661
+ except Exception as e:
662
+ allure.attach(
663
+ f"转换为字符串失败: {str(e)}",
664
+ name="字符串转换错误",
665
+ attachment_type=allure.attachment_type.TEXT
666
+ )
667
+ raise
668
+
669
+
670
+ @keyword_manager.register('转换为整数', [
671
+ {'name': '值', 'mapping': 'value', 'description': '要转换为整数的值'},
672
+ {'name': '进制', 'mapping': 'base',
673
+ 'description': '数字进制(当值为字符串时)', 'default': 10}
674
+ ])
675
+ def convert_to_integer(**kwargs):
676
+ """将值转换为整数
677
+
678
+ Args:
679
+ value: 要转换的值
680
+ base: 数字进制(当值为字符串时),默认为10
681
+
682
+ Returns:
683
+ int: 转换后的整数
684
+ """
685
+ value = kwargs.get('value')
686
+ base = kwargs.get('base', 10)
687
+
688
+ if value is None:
689
+ raise ValueError("值不能为空")
690
+
691
+ try:
692
+ # 如果指定了非10进制,将值转换为字符串再进行进制转换
693
+ if int(base) != 10:
694
+ value_str = str(value)
695
+ result = int(value_str, int(base))
696
+ else:
697
+ result = int(value)
698
+
699
+ with allure.step(f"转换为整数: {type(value).__name__} -> int"):
700
+ allure.attach(
701
+ f"原始值: {value}\n原始类型: {type(value).__name__}\n"
702
+ f"进制: {base}\n转换结果: {result}\n结果类型: {type(result).__name__}",
703
+ name="整数转换结果",
704
+ attachment_type=allure.attachment_type.TEXT
705
+ )
706
+
707
+ return result
708
+ except Exception as e:
709
+ allure.attach(
710
+ f"转换为整数失败: {str(e)}",
711
+ name="整数转换错误",
712
+ attachment_type=allure.attachment_type.TEXT
713
+ )
714
+ raise
715
+
716
+
717
+ @keyword_manager.register('转换为浮点数', [
718
+ {'name': '值', 'mapping': 'value', 'description': '要转换为浮点数的值'}
719
+ ])
720
+ def convert_to_float(**kwargs):
721
+ """将值转换为浮点数
722
+
723
+ Args:
724
+ value: 要转换的值
725
+
726
+ Returns:
727
+ float: 转换后的浮点数
728
+ """
729
+ value = kwargs.get('value')
730
+
731
+ if value is None:
732
+ raise ValueError("值不能为空")
733
+
734
+ try:
735
+ result = float(value)
736
+
737
+ with allure.step(f"转换为浮点数: {type(value).__name__} -> float"):
738
+ allure.attach(
739
+ f"原始值: {value}\n原始类型: {type(value).__name__}\n"
740
+ f"转换结果: {result}\n结果类型: {type(result).__name__}",
741
+ name="浮点数转换结果",
742
+ attachment_type=allure.attachment_type.TEXT
743
+ )
744
+
745
+ return result
746
+ except Exception as e:
747
+ allure.attach(
748
+ f"转换为浮点数失败: {str(e)}",
749
+ name="浮点数转换错误",
750
+ attachment_type=allure.attachment_type.TEXT
751
+ )
752
+ raise
753
+
754
+
755
+ @keyword_manager.register('转换为布尔值', [
756
+ {'name': '值', 'mapping': 'value', 'description': '要转换为布尔值的值'}
757
+ ])
758
+ def convert_to_boolean(**kwargs):
759
+ """将值转换为布尔值
760
+
761
+ Args:
762
+ value: 要转换的值
763
+
764
+ Returns:
765
+ bool: 转换后的布尔值
766
+ """
767
+ value = kwargs.get('value')
768
+
769
+ try:
770
+ result = bool(value)
771
+
772
+ with allure.step(f"转换为布尔值: {type(value).__name__} -> bool"):
773
+ allure.attach(
774
+ f"原始值: {value}\n原始类型: {type(value).__name__}\n"
775
+ f"转换结果: {result}\n结果类型: {type(result).__name__}",
776
+ name="布尔值转换结果",
777
+ attachment_type=allure.attachment_type.TEXT
778
+ )
779
+
780
+ return result
781
+ except Exception as e:
782
+ allure.attach(
783
+ f"转换为布尔值失败: {str(e)}",
784
+ name="布尔值转换错误",
785
+ attachment_type=allure.attachment_type.TEXT
786
+ )
787
+ raise
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pytest-dsl
3
- Version: 0.11.1
3
+ Version: 0.12.0
4
4
  Summary: A DSL testing framework based on pytest
5
5
  Author: Chen Shuanglin
6
6
  License: MIT
@@ -1038,7 +1038,7 @@ jobs:
1038
1038
 
1039
1039
  - name: Run tests
1040
1040
  run: |
1041
- pytest-dsl tests/ --yaml-vars config/ci.yaml --alluredir=allure-results
1041
+ pytest test_runner.py --alluredir=allure-results
1042
1042
 
1043
1043
  - name: Generate report
1044
1044
  uses: simple-elf/allure-report-action@master
@@ -1097,7 +1097,7 @@ CMD ["pytest-dsl", "tests/", "--yaml-vars", "config/prod.yaml"]
1097
1097
  ### 适用场景
1098
1098
 
1099
1099
  - **API接口测试** - 完整的HTTP测试支持
1100
- - **微服务测试** - 分布式测试能力
1100
+ - **分布式测试** - 跨服务调用、服务间通信和分布式系统测试
1101
1101
  - **回归测试** - 数据驱动和批量执行
1102
1102
  - **集成测试** - 跨系统测试协调
1103
1103
  - **性能测试** - 结合其他工具进行性能测试
@@ -1,5 +1,5 @@
1
1
  pytest_dsl/__init__.py,sha256=FzwXGvmuvMhRBKxvCdh1h-yJ2wUOnDxcTbU4Nt5fHn8,301
2
- pytest_dsl/cli.py,sha256=KBuSFwsdbRULxsVscR-2Hffoz-hwSLpJGSsxVnbqtbI,33895
2
+ pytest_dsl/cli.py,sha256=clpvDtQ18tJHl0DUKhoAfCNROE3TB_t59z0fOn5VL9M,33404
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
@@ -12,7 +12,7 @@ pytest_dsl/core/custom_keyword_manager.py,sha256=UdlGUc_mT8hIwmU7LVf4wJLG-geChwY
12
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
- pytest_dsl/core/http_client.py,sha256=Ho1fPl23kYZzDswwAR-YCpgL5c6Oy1bWh_ieDOlgY4s,15808
15
+ pytest_dsl/core/http_client.py,sha256=hdx8gI4JCmq1-96pbiKeyKzSQUzPAi08cRNmljiPQmY,15536
16
16
  pytest_dsl/core/http_request.py,sha256=nGMlx0mFc7rDLIdp9GJ3e09OQH3ryUA56yJdRZ99dOQ,57445
17
17
  pytest_dsl/core/keyword_manager.py,sha256=hoNXHQcumnufPRUobnY0mnku4CHxSg2amwPFby4gQEs,7643
18
18
  pytest_dsl/core/lexer.py,sha256=WaLzt9IhtHiA90Fg2WGgfVztveCUhtgxzANBaEiy-F8,4347
@@ -58,16 +58,16 @@ pytest_dsl/keywords/__init__.py,sha256=5aiyPU_t1UiB2MEZ6M9ffOKnV1mFT_2YHxnZvyWaB
58
58
  pytest_dsl/keywords/assertion_keywords.py,sha256=obW06H_3AizsvEM_9VE2JVuwvgrNVqP1kUTDd3U1SMk,23240
59
59
  pytest_dsl/keywords/global_keywords.py,sha256=4yw5yeXoGf_4W26F39EA2Pp-mH9GiKGy2jKgFO9a_wM,2509
60
60
  pytest_dsl/keywords/http_keywords.py,sha256=z2Brqj1Mkufa_PlZZNwfKuYqkgJhnjsZw-7YNnbt2N4,27302
61
- pytest_dsl/keywords/system_keywords.py,sha256=e65Mzyt56FYmw0vHegajLUSLeEYVI9Y-WSB1h6SKKLo,12089
61
+ pytest_dsl/keywords/system_keywords.py,sha256=hjsACYER87rseSj4thBFnjDqe6At5hBT4Gjifj4ulDE,24470
62
62
  pytest_dsl/remote/__init__.py,sha256=syRSxTlTUfdAPleJnVS4MykRyEN8_SKiqlsn6SlIK8k,120
63
63
  pytest_dsl/remote/hook_manager.py,sha256=0hwRKP8yhcnfAnrrnZGVT-S0TBgo6c0A4qO5XRpvV1U,4899
64
64
  pytest_dsl/remote/keyword_client.py,sha256=BL80MOaLroUi0v-9sLtkJ55g1R0Iw9SE1k11Ifwqx-I,17292
65
65
  pytest_dsl/remote/keyword_server.py,sha256=vGIE3Bhh461xX_u1U-Cf5nrWL2GQFYdtQdcMWfFIYgE,22320
66
66
  pytest_dsl/remote/variable_bridge.py,sha256=dv-d3Gq9ttvvrXM1fdlLtoSOPB6vRp0_GBOwX4wvcy8,7121
67
67
  pytest_dsl/templates/keywords_report.html,sha256=7x84iq6hi08nf1iQ95jZ3izcAUPx6JFm0_8xS85CYws,31241
68
- pytest_dsl-0.11.1.dist-info/licenses/LICENSE,sha256=Rguy8cb9sYhK6cmrBdXvwh94rKVDh2tVZEWptsHIsVM,1071
69
- pytest_dsl-0.11.1.dist-info/METADATA,sha256=5YIMx6SIIlzVFeeuPUhRqi0eISBdDIjpamHlptPjpIY,29642
70
- pytest_dsl-0.11.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
71
- pytest_dsl-0.11.1.dist-info/entry_points.txt,sha256=PLOBbH02OGY1XR1JDKIZB1Em87loUvbgMRWaag-5FhY,204
72
- pytest_dsl-0.11.1.dist-info/top_level.txt,sha256=4CrSx4uNqxj7NvK6k1y2JZrSrJSzi-UvPZdqpUhumWM,11
73
- pytest_dsl-0.11.1.dist-info/RECORD,,
68
+ pytest_dsl-0.12.0.dist-info/licenses/LICENSE,sha256=Rguy8cb9sYhK6cmrBdXvwh94rKVDh2tVZEWptsHIsVM,1071
69
+ pytest_dsl-0.12.0.dist-info/METADATA,sha256=M9J5LQQtA4aCQ3KqCRxjgiDcnZnMc_f_0Yctx91ZpvI,29655
70
+ pytest_dsl-0.12.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
71
+ pytest_dsl-0.12.0.dist-info/entry_points.txt,sha256=PLOBbH02OGY1XR1JDKIZB1Em87loUvbgMRWaag-5FhY,204
72
+ pytest_dsl-0.12.0.dist-info/top_level.txt,sha256=4CrSx4uNqxj7NvK6k1y2JZrSrJSzi-UvPZdqpUhumWM,11
73
+ pytest_dsl-0.12.0.dist-info/RECORD,,