- conftest.py文件专门用来存放fixture的文件,名称固定不能修改。
- conftest.py中的所有方法在调用时都不需要导包
- 一个用例可以同时调用多个conftest.py中的多个方法
- 一般conftest.py中的方法autouse= True, 自动执行。
- conftest.py放在最外层,使用scope= "session"时,整个项目开头执行一次。及时设置为多线程,也是执行一次。
注意,如果全局和子folder下的fixture同名,则最近的fixture起作用,即company下的conftest.py起作用,全局的不会生效
示例
#company下conftest.py import pytest from Common.common import CommonUtil @pytest.fixture(scope = "function",autouse = True,name = "logincompany") def exe_login(): print("Login company" ) yield print("Logout company") @pytest.fixture(scope = "function",autouse = True, name = "username_company") def get_loginusers(): print("the user is company loginuser")
#全局conftest import pytest from Common.common import CommonUtil @pytest.fixture(scope = "function",autouse = True,name = "login") def exe_login(): print("Login system" ) yield print("Logout system") @pytest.fixture(scope = "function",autouse = True, name = "username") def get_loginusers(): print("the user is system loginuser")
标签:company,py,fixture,pytest,conftest,Pytest,print From: https://www.cnblogs.com/woniuguoguo/p/17383337.html