Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can a test in Python unittest get access to the verbosity level?

When calling a test suite in the Python unittest framework, it is possible to give a -v for higher level of verbosity, like:

python3 test_suite.py -v

How can a test case get access to the verbosity level ?

like image 983
EquipDev Avatar asked Mar 24 '17 14:03

EquipDev


1 Answers

The verbosity isn't directly passed to TestCase or TestSuite since none of them actually need it for something. The runner uses the verbosity information (the class running your tests) to handle the amount of information printed out.

Looking at the source, since argv isn't cleared at any point, a non-intrusive way to check for the presense of the verbose flag would be to peek into argv and see if '-v' is inside it.

like image 90
Dimitris Fasarakis Hilliard Avatar answered Sep 25 '22 14:09

Dimitris Fasarakis Hilliard