I have module A that looks like this:
import unittest2 def check_function():
Module A is imported by another module called B. When is the global variable CHECK initialized? When importing? When creating an instance of the class?
I need the CHECK variable to be set every time class A is called. How can I achieve this?
EDIT: I tried the following (which may be what I'm looking for), but CHECK is not set at all inside setUpClass (it remains False, regardless of what check_function () returns).
import unittest2 def check_function():
Any ideas on how to install CHECK once, each time the test is called?
EDIT: check_function () is definitely called once, but I donβt understand why unittest2.skipIf does not βseeβ the value set in setUpClass and adheres to the False value specified in the declaration?
DECISION:
The last skeletal part of the code is as follows:
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)
source share