conftest.py's instructions

1.conftest.py test.py and placed in the same directory, to achieve global unique session level
2. The initialization operation example
in conftest.py file, define a class, the class of the instance variables in the initialization process, you can use the class in which py file. variable to call the object, initialized only once to ensure that
## conftest.py

 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)
  1. autouse difference parameter
    is not used autouse = True, you need to call the initialization method in other test method, you do not need to call autouse = True
  2. After finishing methods can be addfinalizer session

Guess you like

Origin blog.51cto.com/11463754/2467464