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 ?
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 ?
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.
('-v' in argv) or ('--verbose' in argv)
. –
Kneepan © 2022 - 2024 — McMap. All rights reserved.
logging
module and just create a logger for your tests? I think you can pull the logging level from the logger if you need that for something else. – Turbulencelogging
module; thought that the verbosity information may be immediately available. – Kneepanlogging
module. – Turbulencelogging
to print a message accordingly to theverbosity
level as you suggest? – Timmi