0
点赞
收藏
分享

微信扫一扫

Pytest - conftest.py

Spinach菠菜 2023-03-29 阅读 70
  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. ....

'''


举报

相关推荐

0 条评论