zoukankan      html  css  js  c++  java
  • pytest fixture:使用fixture实现用例之间的调用

    pytest fixture

    定义fixture跟定义普通的函数差不多,唯一的区别就是在函数上加个装饰器@pytest.fixture()

    fixture命名不要以test开头,跟用例区别开。fixture是有函数返回值的,没有返回值默认None

    用例调用fixture的返回值,直接就是吧fixture的函数名称当做变量名称

    import pytest
    
    @pytest.fixture()
    def init():
        print('init..')
        return 1
    
    def test1(init):
        print('test1')
    
    def test2(init):
        print('test2')
    
    if __name__ == '__main__':
        pytest.main(['-vs','test06.py'])
  • 相关阅读:
    换零钞
    空心菱形
    生成回文数
    机器人数目
    胡同门牌号
    七星填数
    阶乘位数
    打印数字
    平方末尾
    数位和
  • 原文地址:https://www.cnblogs.com/yronl/p/14463862.html
Copyright © 2011-2022 走看看