zoukankan      html  css  js  c++  java
  • pytest(三十二)--自定义用例顺序(pytest-ordering)

    前言

    测试用例在设计的时候,我们一般要求不要有先后顺序,用例是可以打乱了执行的,这样才能达到测试的效果。

    有些同学在写用例的时候,用例写了先后顺序,有先后顺序后,后面还会有新的问题(如:上个用例返回数据作为下个用例传参,等等一系列的问题)

    github上有个pytest-ordering插件可以控制用例的执行顺序,github插件地址https://github.com/ftobia/pytest-ordering

    环境准备

    先安装依赖包

    pip install pytest-ordering
    

    使用案例

    先看pytest默认的执行顺序,是按test_a.py文件写的用例先后顺序执行的。

    #test_a.py
    import pytest
    def test_a():
        print("用例111")
        assert True
    def test_b():
        print("用例222")
        assert True
    def test_c():
        print("用例333")
        assert True  

     运行结果

     使用pytest-ordering插件后改变测试用例顺序

    #test_a.py
    import pytest
    @pytest.mark.run(order=2)
    def test_a():
        print("用例111")
        assert True
    
    @pytest.mark.run(order=1)
    def test_b():
        print("用例222")
        assert True
    
    @pytest.mark.run(order=3)
    def test_c():
        print("用例333")
        assert True
    

     运行结果

     这样就是按指定的顺序执行的用例

    越努力,越幸运!!! good good study,day day up!!!
  • 相关阅读:
    拆分跨天的时间数据
    模板
    更换数据库服务器迁移步骤
    缺失索引
    flex布局解说和属性
    Vuejs中关于computed、methods、watch,mounted的区别
    皮囊
    回家
    江苏旅游计划
    重写原生alert,弹出层过一会就消失
  • 原文地址:https://www.cnblogs.com/canglongdao/p/13415260.html
Copyright © 2011-2022 走看看