Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use setup and teardown in python

Shulou Source: shulou.com Published: 2022-06-03 17:41:59 11月13日 Update

Editor to share with you how to use setup and teardown in python. I hope you will get something after reading this article. Let's discuss it together.

Description

1. Setup/teardown: each method will be executed once, both inside and outside the class.

2. Setup: the method is executed before it is run, indicating the precondition.

It must be executed once before each use case is executed.

3. Teardown: the method cannot be executed until it is run, which means that the resource is released.

It is executed once after each use case is executed.

Example

# file_name: test_setup.pyimport pytestdef setup (): print ("... out-of-class setup...") def test_create (): print ("out-of-class test_create") def test_view (): print ("out-of-class test_view") class TestSetupClass: def setup (self): print ("... in-class setup...") Def test_create (self): print ("intra-class test_create") def test_view (self): print ("intra-class test_view") def teardown (self): print (". In-class teardown... ") def teardown (): print ("... "out-of-class teardown...") if _ _ name__ = ='_ main__': pytest.main (['- vs', 'test_setup.py']) after reading this article, I believe you have some understanding of "how to use setup and teardown in python". If you want to know more about it, welcome to follow the industry information channel, thank you for reading!

Tags: Methods articles running done examples more conditions knowledge industry resources information information channels or channels Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Xiaomi Apple vpn MariaDB