In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
This paper takes the conftest.py file of Python as an example to analyze the usage of conftest.py file. Read the complete article, I believe that you have a certain understanding of the use of conftest.py files.
1.conftest.py and test.py are placed in the same directory to achieve global uniqueness at the session level.
two。 Examples of initialization operation
In the conftest.py file, define a class, class variables are instantiated in the initialization method, and the class can be used in the py file. Variable to call the object, ensuring that it is initialized only once
# # conftest.py
Class Test1: dr = None # type: classss = None # type:Ssclass Ss: def _ init__ (self): self.__cs = Test1.dr def pr1 (self): print ("method 1" + self.__cs) def pr2 (self): print ("method 2" + self._ _ cs) def close (self): print ("exit") print ("end") @ pytest.fixture (scope='session') Autouse=True) def chishihua (request): Test1.dr = "ces" Test1.classss = Ss () print ("all") def fin (): Test1.classss.close () # differences in autouse parameters for close operation request.addfinalizer (fin)
Do not use autouse=True, you need to call the initialization method in other test methods, and if you use autouse=True, you do not need to call the addfinalizer method to finish the work after session. Do you have any further understanding of the use of conftest.py files? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel. Thank you for reading.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.