zoukankan      html  css  js  c++  java
  • python之fixture作用域

    @pytest.fixture()

    1、fixture命名不要以test开头

    2、fixture是有返回值得,没有返回值默认为None

    3、默念作用域是function

    4、可以写在conftest.py,也不可以不写

     测试文件.py

    class Testb(object):
        datas = ['zhangsan1','lisi1']
        @pytest.mark.parametrize('data', datas)
        def test0002(self,data,writeb):
            print("传参:",data)
            return data
    class Testa(object):
        datas = ['zhangsan','lisi']
        @pytest.mark.parametrize('data', datas)
        def test0002(self,data,writeb):
            print("传参:",data)
            return data
    

    作用域:module,.py只执行一次“开始”

    conftest.py

    @pytest.fixture(scope="module")
    def writeb():
        print("开始")
        yield
        # print("从testd拿值",datas)
        print("结束")
    

    打印结果

    作用域:class,每个类只执行一次“开始”,一共有2个类,所以执行2次

    conftest.py

    @pytest.fixture(scope="class")
    def writeb():
        print("开始")
        yield
        # print("从testd拿值",datas)
        print("结束")

    打印结果

     作用域:session,所有案例执行只执行一次,“开始”

    conftest.py

    @pytest.fixture(scope="session")
    def writeb():
        print("开始")
        yield
        # print("从testd拿值",datas)
        print("结束")
    

    打印结果

    作用域:function,每个案例都执行一次,一共4条案例,执行4次“开始”

    conftest.py

    @pytest.fixture(scope="function")
    def writeb():
        print("开始")
        yield
        # print("从testd拿值",datas)
        print("结束")
    

    打印结果

    上班求生存,下班求发展
  • 相关阅读:
    kuangbin_ShortPath P (HDU 4725)
    kuangbin_ShortPath O (LightOJ 1074)
    方法的定义格式
    A Better Finder Rename 9.40 Key
    [iOS] 初探 iOS8 中的 Size Class
    iOS 后台执行
    iOS7 毛玻璃效果
    PhpStorm8 注册码
    [教程] 【终极开关机加速!!】手把手教你加速Mac的开关机速度。(经验证适用10.10!)
    iOS 取应用版本
  • 原文地址:https://www.cnblogs.com/ljf520hj/p/15632798.html
Copyright © 2011-2022 走看看