Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use Fixture module level in python

Shulou Source: shulou.com Published: 2022-06-03 15:33:52 11月09日 Update

This article mainly introduces how to use the Fixture module level in python. It is very detailed and has a certain reference value. Friends who are interested must finish it!

Description

1. No matter how many classes are in the py file and how many methods are in the class, they can only be executed automatically once.

2. DefsetUpModule () is called automatically when the py file starts.

3. When the py file ends, deftearDownModule () is called automatically.

Example

Import unittest def setUpModule (): print ("setUpModule automatically called") def tearDownModule (): print ("tearDownModule automatically called") def my_sum (a B): return a + b class my_test1 (unittest.TestCase): @ classmethod def setUpClass (cls): print ("setupclass automatically called") @ classmethod def tearDownClass (cls): print ("teardownclass automatically called") def setUp (self): print ("setup is automatically called") def tearDown (self): print ("teardown is automatically called") Def test_001 (self): print (my_sum (5 6) def test_002 (self): print (my_sum (0) 3) class my_test2 (unittest.TestCase): @ classmethod def setUpClass (cls): print ("setupclass automatically called") @ classmethod def tearDownClass (cls): print ("teardownclass automatically called") def setUp (self): print ("setup is automatically called") def tearDown (self): print ("teardown is automatically called") def test_001 ( Self): print (my_sum (5) 6) def test_002 (self): print (my_sum (0,3)) are all the contents of the article "how to use Fixture Module level in python" Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Tags: Documents modules content articles values interests examples guys partners methods more knowledge industry information information channels channels references help Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Huawei NVidia macOS Shulou Tech Info