fixtures

"" " 
In front of the concept of fixtures has been brief, can vividly see it as two outer layers of biscuit sandwich crackers,
two chip cookies is setUp / tearDown, the middle of the heart is the test case. In addition it outside, the unittest also provides a greater range of fixtures,
for example fixtures test classes and modules.
"" "
Import the unittest
DEF setUpModule ():
Print (" Start test Module1 >>>>>>>>>> ")

DEF tearDownModule ():
Print ( "the Test Module End >>>>>>>>>>>>>>")

class the Test (unittest.TestCase):
@classmethod
DEF setUpClass (CLS):
Print ( "Start the Test class == =====> ")

@classmethod
DEF tearDownClass (CLS):
Print (" End the Test class =====> ")

DEF the setUp (Self):
print("test case start -->")

def tearDown(self):
print("test case end -->")

test_case DEF (Self):
Print ( "Test Case1")

DEF Case2 (Self):
Print ( "Test Case2")

IF the __name__ == '__main__':
unittest.main ()

"" "
setUpModule / tearDownModule: the whole module It began to be executed at the end.
setUpClass / tearDownClass: to be performed at the beginning and end of the test class.
the setUp / tearDown: to be performed at the beginning and end of the test case.
It should be noted, setUpClass / tearDownClass slightly different wording first of all, need to
be @classmethod decoration, method parameters followed for cls. in fact, cls with self and nothing special,
only represents a method parameter class, but everyone convention, so accustomed to name, Of course, also be used instead of abc.
"" "

Guess you like

Origin www.cnblogs.com/zhang-da/p/12210772.html