Pytest - conftest.py

2023年3月30日
  1. conftest.py
import pytest

@pytest.fixture(scope="function", autouse=False, name = "db")    
def exec_db_sql(request):                                                       
    print("执行SQL...")    
    assert 1==1                             # 用于实际与期望是否相等                        
    yield                                                                                                         
    print("关闭数据库")

  1. 用例
import pytest


class Test_Run1():
    def test1(self,db):
        print("测试1.....")
    
    def test2(self):                                                # 调用
        print("测试2..... " )                                     # 打印参数

    def test3(self):                                 
        print("测试3.....")

'''
fixture优先级:

会话:session -> 
类:class 
类:setup_class 
函数:function 
      setup

'''


'''
pytest执行过程:
1. 查询当前目录下的conftest.py
2. 查询pytest.ini
3. ....

'''

服务器托管,北京服务器托管,服务器租用 http://www.hhisp.net
机房租用,北京机房租用,IDC机房托管, http://www.e1idc.net

hackdl

咨询热线/微信 13051898268