Suppose I have this integration test
class TestClass(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.key = '123'
def test_01_create_acc(self):
user = create_account(...)
self.key = user.key
def test_02_check_account(self):
user = check_account(..)
self.assertEqual(self.key, user.key)
It looks like the attribute self.key is not mutable. It stays with the old value from setUpClass. But isn't setUpClass only called once?
The account function creates a key randomly for security reason, so I am not allowed to pass in my secret key. It returns the key, so I need to modify that attribute. Can I?
It looks like each test_ case is isolated.
my_gloabl = None
def setUpClass(cls):
cls.key = my_global
If I change my_global in test1, test2 will get None.