We are doing automated testing time, sometimes you want to clearly see the details of each use case execution, we can set the parameters by unittest in verbosity
verbosity parameter settings
verbosity represents only during the execution of the embodiments may be used in the implementation of the embodiment according to the different configuration parameters represent different levels of detail, we look at how to interpret the source code.
We can see by observing the verbosity defaults to 1, it can be set to 0 and 2.
- 0 (silent mode): You can only get the total number of test cases and the overall result.
- 1 (default mode): the silent mode is very similar to the foregoing embodiment except the successful use have each failed in each of the foregoing embodiments have used "E" "."
- 2 (verbose mode): The test results will show all the relevant information for each test case and you add different parameters on the command line can play the same effect
Look so much better to our practice.
Small scale chopper
We look at each case together verbosity by unittest results and our previous written inquiry music
verbosity=0
0 (silent mode): You can only get the total number of test cases and the overall result.
# coding:utf-8 import unittest import requests class Music(unittest.TestCase): def select(self,name): url = 'https://api.apiopen.top/searchMusic' data = { "name":name } r = requests.post(url,data=data) b = r.json()['result'][0]['title'] return b # Error use cases DEF Test01 (Self): B = ' Broken Bridge story ' A = self.select (B) self.assertEqual(b,a) Print ( ' This embodiment is a ' ) # Error use cases DEF Test02 (Self): A = ' that good cry story ' B = self.select (A) self.assertEqual(a,b) Print ( ' This is according to the second ' ) # Correct use cases DEF TEST03 (Self): A = ' Mangzhong ' B = self.select (A) self.assertEqual(a,b) Print ( ' This is according to a third ' ) if __name__ == '__main__': unittest.main(verbosity=0)
After the execution, we can see through when vervbosity = 0 when only shows the implementation of mistake how many use cases
vervbosity=1
1 (default mode): the silent mode is very similar to the foregoing embodiment except the successful use have each failed in each of the foregoing embodiments have used "E" "."
# coding:utf-8 import unittest import requests class Music(unittest.TestCase): def select(self,name): url = 'https://api.apiopen.top/searchMusic' data = { "name":name } r = requests.post(url,data=data) b = r.json()['result'][0]['title'] return b # Error use cases DEF Test01 (Self): B = ' Broken Bridge story ' A = self.select (B) self.assertEqual(b,a) Print ( ' This embodiment is a ' ) # Error use cases DEF Test02 (Self): A = ' that good cry story ' B = self.select (A) self.assertEqual(a,b) Print ( ' This is according to the second ' ) # Correct use cases DEF TEST03 (Self): A = ' Mangzhong ' B = self.select (A) self.assertEqual(a,b) Print ( ' This is according to a third ' ) if __name__ == '__main__': unittest.main(verbosity=1)
After the execution, we can see through when vervbosity = 1 when the successful use case., Said the failure represented by E
vervbosity=2
2 (verbose mode): The test results will show all the relevant information for each test case and you add different parameters on the command line can play the same effect
# coding:utf-8 import unittest import requests class Music(unittest.TestCase): def select(self,name): url = 'https://api.apiopen.top/searchMusic' data = { "name":name } r = requests.post(url,data=data) b = r.json()['result'][0]['title'] return b # Error use cases DEF Test01 (Self): B = ' Broken Bridge story ' A = self.select (B) self.assertEqual(b,a) Print ( ' This embodiment is a ' ) # Error use cases DEF Test02 (Self): A = ' that good cry story ' B = self.select (A) self.assertEqual(a,b) Print ( ' This is according to the second ' ) # Correct use cases DEF TEST03 (Self): A = ' Mangzhong ' B = self.select (A) self.assertEqual(a,b) Print ( ' This is according to a third ' ) if __name__ == '__main__': unittest.main(verbosity=2)
After performing discovery verbosity = 2, executing the use case with the embodiment executed before detailed print out
Repeat this one more code just to facilitate understanding of the contents of each parameter indicates the verbosity setting detailed display for everyone, you can also try their own hands