1.conftest.py与test.py放在同一个目录下,用于实现session级别的全局惟一
2.初始化操做举例
在conftest.py文件中,定义一个类,类变量在在初始化方法中实例化,在里面py文件中就均可以使用该类.变量来调用该对象,保证只初始化一次
## conftest.pysession
class Test1: dr = None # type: classss = None # type:Ss class Ss: def __init__(self): self.__cs = Test1.dr def pr1(self): print("方法1" + self.__cs) def pr2(self): print("方法2" + self.__cs) def close(self): print("退出") print("结束") @pytest.fixture(scope='session', autouse=True) def chishihua(request): Test1.dr = "ces" Test1.classss = Ss() print("全部") def fin(): Test1.classss.close() # 关闭操做 request.addfinalizer(fin)