码迷,mamicode.com
首页 > 其他好文 > 详细

pytest文档2--firture之conftest.py

时间:2020-05-13 12:11:39      阅读:53      评论:0      收藏:0      [点我收藏+]

标签:注意   登陆   nbsp   rtu   ==   调用   __init__   name   bsp   

conftest.py配置

1.上面一个案例是在同一个.py文件中,多个用例调用一个登陆功能,如果有多个.py的文件都需要调用这个登陆功能的话,那就不能把登陆写到用例里面去了。
此时应该要有一个配置文件,单独管理一些预置的操作场景,pytest里面默认读取conftest.py里面的配置

conftest.py配置需要注意以下点:

  • conftest.py配置脚本名称是固定的,不能改名称
  • conftest.py与运行的用例要在同一个pakage下,并且有__init__.py文件
  • 不需要import导入 conftest.py,pytest用例会自动查找

示例

__init__.py

conftest.py
    # coding:utf-8
    import pytest

    @pytest.fixture()
    def login():
        print("输入账号,密码先登录")

test_fix1.py
    # coding:utf-8
    import pytest
    
    def test_s1(login):
        print("用例1:登录之后其它动作111")
    
    def test_s2():  # 不传login
        print("用例2:不需要登录,操作222")
    
    def test_s3(login):
        print("用例3:登录之后其它动作333")
    
    if __name__ == "__main__":
        pytest.main(["-s", "test_fix1.py"])

test_fix2.py
    # coding:utf-8
    import pytest
    
    def test_s4(login):
        print("用例4:登录之后其它动作111")
    
    def test_s5():  # 不传login
        print("用例5:不需要登录,操作222")
    
    if __name__ == "__main__":
        pytest.main(["-s", "test_fix2.py"])

 

pytest文档2--firture之conftest.py

标签:注意   登陆   nbsp   rtu   ==   调用   __init__   name   bsp   

原文地址:https://www.cnblogs.com/qiqi-yhq/p/12881339.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!