How to initialize global variable at each class invocation?
<p>I have a module A who looks like the following:</p>

<pre><code>import unittest2

def check_function():
    # performs actions and returns True or False
    return smth

CHECK = check_function()

class A(unittest2.TestCase):

    @unittest2.skipIf(CHECK, "skip message 1")
    def test_1(self):
        # test check

    @unittest2.skipIf(CHECK, "skip message 2")
    def test_2(self):
        # test check
</code></pre>

<p>Module A is being imported by another module, called B. 
When is the global variable CHECK initialized? At import? At class instantiation? </p>

<p>I need to have the CHECK variable set each time class A is called. How can I achieve this?</p>

<p>EDIT:
I have tried the following (which might be what I am looking for), but CHECK is not set at all inside setUpClass (it stays False, no matter what check_function() returns).</p>

<pre><code>import unittest2

def check_function():
    # performs actions and returns True or False
    return smth

CHECK = False

class A(unittest2.TestCase):

    global CHECK

    @classmethod
    def setUpClass(cls):
        CHECK = check_function()

    @unittest2.skipIf(CHECK, "skip message 1")
    def test_1(self):
        # test check

    @unittest2.skipIf(CHECK, "skip message 2")
    def test_2(self):
        # test check
</code></pre>

<p>Any ideas of how to set CHECK once, each time the test is invoked?</p>

<p>EDIT:
check_function() is certainly called once, but I don't understand why unittest2.skipIf does not "see" the value set in setUpClass, and sticks to the False value set at declaration?</p>

<p>SOLUTION:</p>

<p>The final skeletopn of the code looks like this:</p>

<pre><code>import unittest2

def check_function():
    # performs checks and returns True or False
    return smth

class A(unittest2.TestCase):

    CHECK = check_function()

    @unittest2.skipIf(CHECK, "skip message 1")
    def test_1(self):
        # do tests
        self.assertTrue(True)

    @unittest2.skipIf(CHECK, "skip message 1")
    def test_2(self):
        # do tests
        self.assertTrue(True)
</code></pre>
