python unittest setup teardown

Solutions on MaxInterview for python unittest setup teardown by the best coders in the world

showing results for - "python unittest setup teardown"
Paola
03 Apr 2020
1#!/usr/bin/env python
2# -*- coding:utf-8 -*-
3# @FileName  :Use case preconditions.py
4# @Time      :2020\10\28 0028 22:22
5# @Author    :Krystal
6# @Desc      :Testcase
7
8import unittest
9
10class Test(unittest.TestCase):
11    @classmethod
12    def setUpClass(cls):
13        # It executes once before all use cases run
14        print('SetUpClass')
15
16    @classmethod
17    def tearDownClass(cls):
18        # After all the use cases have been run, it is executed once
19        print('tearDownClass')
20
21    def tearDown(self):
22        # Each test case is executed after it is run
23        print('tearDown')
24
25    def setUp(self):
26        # Each test case is executed before it is run
27        print('setUp')
28
29    def testa(self):
30        print('testa')
31
32    def testz(self):
33        print('testz')
34
35    def testb(self):
36        print('testb')
37
38    def testc(self):
39        print('testc')
40
41
42if __name__ == "__main__":
43    unittest.main()