Python unittest give '.', E or F on ok, error or fail. We can avoid it by setting verbosity = 0, or /dev/null. but how can we change it. I mean I want to write after every test PASS, FAIL or ERROR instead of ., E or F, without using verbosity flag -V for output.
I am looking for following kind of output:
Thanks Zubair
So using extra verbosity (-v
) on the command line gets the desired output format:
Passing the -v option to your test script will instruct
unittest.main()
to enable a higher level of verbosity, and produce the following output:
test_isupper (__main__.TestStringMethods) ... ok test_split (__main__.TestStringMethods) ... ok test_upper (__main__.TestStringMethods) ... ok ---------------------------------------------------------------------- Ran 3 tests in 0.001s OK
(https://docs.python.org/3/library/unittest.html#basic-example)
But we can also set the verbosity level from code:
You can run tests with more detailed information by passing in the verbosity argument:
if __name__ == '__main__': unittest.main(verbosity=2)
(https://docs.python.org/3/library/unittest.html#unittest.main)
If you want to further customize the output, see Stef's answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With