unittest 框架可以通过给TestCase类赋予属性,然后在测试文件中通过getattr(self, '属性名')获取改属性
例:
import unittest
class TestNew(unittest.TestCase):
def setUp(self) ->None:
unittest.TestCase.cluster =123
unittest.TestCase.__setattr__(self, "param1", "value1")
def test_1(self):
print(getattr(self, "cluster"))
print(getattr(self, 'param1'))
assert 1
if __name__ =='__main__':
unittest.main()