Fwd: python unit test framework sample code

Ganesh Pal ganesh1pal at gmail.com
Mon Jan 11 05:05:51 EST 2016


Totally stuck with this
On Jan 10, 2016 7:11 PM, "Ganesh Pal" <ganesh1pal at gmail.com> wrote:

> Apologies,  looks like I did a reply instead of reply-all. So
> forwarding this email , please provide guidance on the same
>
> ---------- Forwarded message ----------
> From: Ganesh Pal <ganesh1pal at gmail.com>
> Date: Thu, Jan 7, 2016 at 12:26 PM
> Subject: Re: python unit test framework sample code
> To: Terry Reedy <tjreedy at udel.edu>
>
> > Unless you have a large program already in 2.6 and are just adding tests
> > (perhaps so you can more easily upgrade someday), consider upgrading to a
> > newer version.
>
> Sure , but for now Iam limited to use 2.6 , hence I cant upgrade need
> to work with 2.6
>
> >>
> >> class FileSystemTest(unittest2.TestCase):
> >>      block_address = {}
> >>      report = ""
> >>
> >>      @classmethod
> >>      def setUpClass(cls):
> >>          cls.FileSystemSetup()
> >
> >
> > This is senseless.  Put the body of FileSystemSetup here.
>
> I didn't understand  which line is senseless. I was trying to refer
> this example on stack overflow
>
> http://stackoverflow.com/questions/5938517/not-able-call-a-local-method-from-setupclass
>
>
> class TestSystemPromotion(unittest2.TestCase):
>
>   @classmethod
>   def setUpClass(cls):
>     cls.setup_test_data()
>
>
>   @classmethod
>   def setup_test_data(cls):
>     ...
>
>   def test_something(self):
>     ...
>
>
> class FileSystemTest(unittest2.TestCase):
>     block_address = {}
>     report = ""
>
>     @classmethod
>     def setUpClass(cls):
>         cls.FileSystemSetup()
>
>     @classmethod
>     def FileSystemSetup(cls):
>         """
>         Initial setup before unittest is run
>         """
>         logging.info("SETUP.....Started !!!")
>
> >>      def inode_corruption(self):
> >>          """ test_01: inode  corruption """
> >>          self.assertTrue(corrupt.run_query_tool(self.__class__.report,
> >
> >
> > self.block_address['test_01']))
> >
> > Assuming that unittest2 is same as unittest, test methods must be called
> > test_xyz.  So this is not run, hence no error.
>
> Sorry  I have changed this from inode_corruption' to 'test_inode_corruption
>
> >
> >>      @classmethod
> >>      def tearDownClass(cls):
> >>          cls.tearDown()
> >
> >
> > Ditto.  Put real body here.
> >
> >>      @classmethod
> >>      def tearDown(cls):
> >
> >
>
> > The above refers to functions you did not post.  For current unittest, it
> > looks likes you should be using a setUpModule (possible tearDownModule)
> > functions, but I don't know if those are available in the older
> unittest2.
>
>
> we have tearDownClass and setUpClass in python 2.6 and under unittest2
>
> >>> help(unittest2.TestCase.tearDownClass)
> Help on method tearDownClass in module unittest2.case:
>
> tearDownClass(cls) method of __builtin__.type instance
>     Hook method for deconstructing the class fixture after running all
> tests in the class.
>
> >>> help(unittest2.TestCase.setUpClass)
> Help on method setUpClass in module unittest2.case:
>
> setUpClass(cls) method of __builtin__.type instance
>     Hook method for setting up class fixture before running tests in the
> class.
>
> Regards,
> Ganesh
>



More information about the Python-list mailing list