zoukankan      html  css  js  c++  java
  • pytest的conftest使用

    项目test下的目录结构

     

    全局conftest.py

    import pytest
    # 当autouse=False时,测试用例需要传入参数,为True时,不需要传入参数
    @pytest.fixture(scope="session",autouse=True)
    def start():
        print('
    打开首页')
        # flag = 1
        # yield flag
        # print('退出登录')

    suite1/conftest.py

    import pytest
    # 当autouse=False时,测试用例需要传入参数,为True时,不需要传入参数
    @pytest.fixture(scope="module")
    def open_web1():
        print('
    打开页面1')

    suite1/test_1.py

    import pytest
    def test_03(start,open_web1):
        print('测试用例3操作')
    def test_04(start,open_web1):
        print('测试用例4操作')
    
    if __name__ == "__main__":
        pytest.main(["-s", "test_1.py"])

    suite1/test_2.py

    import pytest
    def test_05(start,open_web1):
        print('测试用例5操作')
    def test_06(start,open_web1):
        print('测试用例6操作')
    
    if __name__ == "__main__":
        pytest.main(["-s", "test_2.py"])

    suite2/conftest.py

    import pytest
    # 当autouse=False时,测试用例需要传入参数,为True时,不需要传入参数
    @pytest.fixture(scope="function")
    def open_web2():
        print('
    打开页面2')

    suite2/test_3.py

    import pytest
    def test_07(start,open_web2):
        print('测试用例7操作')
    def test_08(start,open_web2):
        print('测试用例8操作')
    
    if __name__ == '__main__':
        pytest.main(["-s", "test_3.py"])

    suite2/test_4.py

    import pytest
    def test_09(start,open_web2):
        print('测试用例9操作')
    def test_10(start,open_web2):
        print('测试用例10操作')
    if __name__ == '__main__':
        pytest.main(["-s", "test_4.py"])

    执行测试

     

  • 相关阅读:
    搭建CentOS在线yum源镜像服务器
    zabbix-使用orabbix来监控oracle11g
    zabbix监控系统-1:系统搭建
    ELK-学习-1:elasticsearch6.3安装和配置
    zabbix-使用percona mysql插件来监控mysql
    zabbix学习基础篇-4:用户群组和用户
    相关性分析
    马尔可夫预测
    该工程中的宏被禁止,请参阅联机帮助
    matlab工具包
  • 原文地址:https://www.cnblogs.com/aiyumo/p/12890437.html
Copyright © 2011-2022 走看看