3

I would like to use python unittest setUpClass and tearDownClass methods with arguments. More specifically, here is what I am doing now:

import unittest2 as unittest
cache = VCache(arg1, arg2, arg3)

class Validation(unittest.TestCase):
    ''' Unit test class with a local cache to avoid intensive network traffic. '''

    @classmethod
    def setUpClass(cls):
        ''' Copy all required data locally. '''
        super(Validation, cls).setUpClass()
        cache.setUp()

    @classmethod
    def tearDownClass(cls):
        ''' Remove the cache. '''
        super(Validation, cls).tearDownClass()
        cache.tearDown()

It works but now I would like to wrap the cache management in a subclass of Validation, to avoid using a global variable and writing the setUpClass and tearDownClass everytime.

This does not work of course because setUpClass() and tearDownClass() do not accept arguments. Any solution?

dr.haz
  • 1,497
  • 1
  • 10
  • 5
  • 2
    I'm confused by this question. The whole point of setUpClass is that it only runs once for a set of tests. – szeitlin Sep 01 '15 at 16:49

0 Answers0