Skipping test using unittest SkipTest and exit status
Steven D'Aprano
steve at pearwood.info
Fri May 13 12:51:38 EDT 2016
On Sat, 14 May 2016 02:23 am, Ganesh Pal wrote:
> Hi Team,
>
> Iam on python 2.7 and Linux . I need inputs on the below program ,
"I am" is two words, not one. I hope you wouldn't write "Youare"
or "Heis" :-) Whenever you write "Iam", I read it as the name "Ian", which
is very distracting.
> Iam skipping the unittest from setUpClass in following way # raise
> unittest.SkipTest(message)
>
> The test are getting skipped but I have two problem .
>
> (1) This script is in turn read by other scripts which considers the
> test have passed based on the scripts return code , but the test have
> actually been skipped , How do include an exit status to indicates that
> the test have failed
But the test *hasn't* failed. A skipped test is not a failed test.
If you want the test to count as failed, you must let it fail. You can use
the fail() method for that.
https://docs.python.org/2/library/unittest.html#unittest.TestCase.fail
> (2) Why is the message in the raise statement i.e raise
> unittest.SkipTest("Class setup failed skipping test") not getting
> displayed .
Raising a SkipTest exception is equivalent to calling the skipTest method,
which marks the test as an expected skipped test, not a failure. Since it
is not a failure, it doesn't display the exception.
If you run unittest in verbose mode, the skip message will be displayed. See
the documentation here:
https://docs.python.org/2/library/unittest.html#skipping-tests-and-expected-failures
--
Steven
More information about the Python-list
mailing list