Skip to main content

对Python unittest的功能进行了扩展

Project description

dup

  • dup主要utx的修改,对由python3.5的支持转换为python2.7

    • 支持Python2.7
  • 安装dup

    pip install dup
    
  • 功能列表

    • 用例排序,只需要导入dup库,用例的执行顺序就会和编写顺序一致
    • 用例自定义标签,可以对测试用例指定多个标签。 目前全部用例默认带有FULL标签,未指定标签的用例,默认带有SMOKEFULL两个标签。
  • 示例

    @unique
    class Tag(Enum):
        SMOKE = 1  # 冒烟测试标记,可以重命名,但是不要删除
        FULL = 1000  # 完整测试标记,可以重命名,但是不要删除
    
        # 以下开始为扩展标签,自行调整
        SP = 2
    
    class TestLegion(unittest.TestCase):
    
        @tag(Tag.SMOKE)
        def test_create_legion(self):
            pass
    
        @tag(Tag.SP, Tag.FULL)
        def test_quit_legion(self):
            """退出军团
    
            :return:
            """
            print("吧啦啦啦啦啦啦")
            assert 1 == 2
    
  • 运行指定标签的测试用例

    from dup import *
    
    if __name__ == '__main__':
        setting.run_case = {Tag.SMOKE}  # 只运行SMOKE冒烟用例
        runner = TestRunner()
        runner.add_case_dir(r"testcase")
        runner.run_test(report_title='接口自动化测试报告')
    
  • 数据驱动

    class TestLegion(unittest.TestCase):
    
        @data(["gold", 100], ["diamond", 500])
        def test_bless(self, bless_type, award):
            print(bless_type)
            print(award)
    
        @data(10001, 10002, 10003)
        def test_receive_bless_box(self, box_id):
            """ 领取祈福宝箱
    
            :return:
            """
            print(box_id)
    
  • 默认会解包测试数据来一一对应函数参数,可以使用unpack=False,不进行解包

     class TestBattle(unittest.TestCase):
         @data({"gold": 1000, "diamond": 100}, {"gold": 2000, "diamond": 200}, unpack=False)
         def test_get_battle_reward(self, reward):
             """ 领取战斗奖励
    
             :return:
             """
             print(reward)
             print("获得的钻石数量是:{}".format(reward['diamond']))
    
  • 检测用例是否编写了用例描述

    2017-11-13 12:00:19,334 WARNING legion.test_legion.test_bless没有用例描述
    
  • 执行测试时,显示测试进度

    2017-11-13 12:00:19,336 INFO 开始进行测试
    2017-11-13 12:00:19,436 INFO Start to test legion.test_legion.test_create_legion (1/5)
    2017-11-13 12:00:19,536 INFO Start to test legion.test_legion.test_receive_bless_box (2/5)
    2017-11-13 12:00:19,637 INFO Start to test legion.test_legion.test_receive_bless_box (3/5)
    2017-11-13 12:00:19,737 INFO Start to test legion.test_legion.test_receive_bless_box (4/5)
    2017-11-13 12:00:19,837 INFO Start to test legion.test_legion.test_quit_legion (5/5)
    
  • setting类提供多个设置选项进行配置

    class setting:
    
        # 只运行的用例类型
        run_case = {Tag.SMOKE}
    
        # 开启用例排序
        sort_case = True
    
        # 每个用例的执行间隔,单位是秒
        execute_interval = 0.1
    
        # 开启检测用例描述
        check_case_doc = True
    
        # 显示完整用例名字(函数名字+参数信息)
        full_case_name = False
    
        # 测试报告显示的用例名字最大程度
        max_case_name_len = 80
    
        # 执行用例的时候,显示报错信息
        show_error_traceback = True
    
        # 生成ztest风格的报告
        create_ztest_style_report = True
    
        # 生成bstest风格的报告
        create_bstest_style_report = True
    
  • 集成 ztestBSTestRunner 自动生成两份测试报告,感谢两位作者的测试报告模版

  • ztest风格

    ztest风格

  • bstest风格

    bstest风格

  • 无缝接入unittest项目,导入utx包即可开始使用扩展功能,无需修改之前的代码

更新 1.1.1:

去除 跳过用例数,增加用例程序错误数

更新1.1.2:

更新内容:

  1、修复展示文本溢出无法收缩的问题
  2、case 增加报告负责人列(需要在 case 类文件注释里  增加【xx】 xx 【】为中文符号 代表 case 负责人 )

更新1.1.3:

更新内容:

run方法增加返回值

更新1.1.4:

更新内容: case 返回 unittest 用例名,去除 _

更新1.1.5:

更新内容: case 执行时间返回格式改为秒级别

更新1.1.6:

更新内容:失败case 或者 错误case 增加case 层面的重试。
runner = TestRunner()
runner.run_test() 方法增加可选参数: retry=0 (重试次数)

更新1.1.7:

更新内容:多进程执行自动化时,有偶现的报错,当前版本fix了该问题。

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dup-1.1.7.tar.gz (41.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dup-1.1.7-py2-none-any.whl (41.5 kB view details)

Uploaded Python 2

File details

Details for the file dup-1.1.7.tar.gz.

File metadata

  • Download URL: dup-1.1.7.tar.gz
  • Upload date:
  • Size: 41.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.6.1 requests/2.25.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.52.0 CPython/2.7.16

File hashes

Hashes for dup-1.1.7.tar.gz
Algorithm Hash digest
SHA256 bbecc8b0f231c84f4f0b7620dc5cc8f1d56bb7838b9e133451db3d7232ec256c
MD5 3c1d76dc7f64e5868f76c1598258bc22
BLAKE2b-256 5c359624b73e0cdf5dc08d08928fafb6e63512a7d637e05ec091fc5f0bfe4d7f

See more details on using hashes here.

File details

Details for the file dup-1.1.7-py2-none-any.whl.

File metadata

  • Download URL: dup-1.1.7-py2-none-any.whl
  • Upload date:
  • Size: 41.5 kB
  • Tags: Python 2
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.6.1 requests/2.25.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.52.0 CPython/2.7.16

File hashes

Hashes for dup-1.1.7-py2-none-any.whl
Algorithm Hash digest
SHA256 1ce7c3f89f5f2e763de47752df9f14fa6e9892b1c68d040382507d1566d38fa6
MD5 5efd53c42736b7dac7c2f7ad6b20bc90
BLAKE2b-256 16f5486275598a89f0fc06fc012c61a28b92b234e858a64498d6083397938cab

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page