Skipping test using unittest SkipTest and exit status

Ganesh Pal ganesh1pal at gmail.com
Sat May 14 10:28:24 EDT 2016


>
> > 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.
>
>
 I am lazy fellow  and you are smart guy.  just a sentence with few words .
 Take care  :)


> > 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
>
>

1.  How about raising failureException :

I was thinking of using  failureException instead of fail() method , If I
replace my code with raise unittest.TestCase.failureException("class setup
failed")

The script show the below output , this looks fine for me. Do you see any
problems with this ?

gpal-ae9703e-1# python unitest1.py
ERROR:root:Failed scanning
E
======================================================================
ERROR: setUpClass (__main__.ScanTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "unitest1.py", line 20, in setUpClass
    raise unittest.TestCase.failureException("class setup failed")
AssertionError: class setup failed

----------------------------------------------------------------------
Ran 0 tests in 0.000s

FAILED (errors=1)

2. I find  assert and raise RunTimeError also fitting my program  ,please
suggest whats best  form unittest fixture point of view.


         if not self.scan:
            logging.error("Failed scanning ")
            assert False, "Class setup failed skipping test"

        if not self.scan:
            logging.error("Failed scanning ")
            raise  RuntimeError.

 My overall ,idea is Setup class fails then don't run any of the next
statements and exit the tests.


Regards,
Ganesh



More information about the Python-list mailing list