Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #103312

Re: Python unittest2.SkipTest and general suggestion

From Ganesh Pal <ganesh1pal@gmail.com>
Newsgroups comp.lang.python
Subject Re: Python unittest2.SkipTest and general suggestion
Date 2016-02-21 23:33 +0530
Message-ID <mailman.19.1456077794.20994.python-list@python.org> (permalink)
References <CACT3xuUvzKN=WoE-+E2a+stOmDmmBTdp90ZOxxLydkyH2XuGhA@mail.gmail.com> <85d1rq0zed.fsf@benfinney.id.au>

Show all headers | View raw


On Sun, Feb 21, 2016 at 10:33 PM, Ben Finney <ben+python@benfinney.id.au> wrote:

> You are already supplying a custom message to ‘self.skipTest’::
>
>     except Exception as exc:
>         logging.error(exc)
>         raise unittest.SkipTest("Failure running Integrity Scan ")
>
> So you can change that message by including the text representation of
> the exception object::
>
>     except Exception as exc:
>         logging.error(exc)
>         raise unittest.SkipTest(
>                 "Failure running Integrity Scan: {exc}".format(exc=exc))
>


Thank you for the pointers , but I modified my code to use raise
instead of exception , just wondering how will I display the message
with the below code ,

Sample code :

import os
try:
    import unittest2 as unittest
except ImportError:
    import unittest

class MyTests(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        #x = False
        x = None
        if not x:
            raise unittest.SkipTest(
                "class setup failed")

    def test_one(self):
        print "test_one"

    def test_two(self):
        print "test_two"

if __name__ == "__main__":
    unittest.main()

output:

gpal-3c6dc81-1# python c_4.py
s
----------------------------------------------------------------------
Ran 0 tests in 0.000s

OK (skipped=1)

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Python unittest2.SkipTest and general suggestion Ganesh Pal <ganesh1pal@gmail.com> - 2016-02-21 23:33 +0530

csiph-web