47
在unittest的setUp()方法中,我已经设置了一些自我变量,这些变量稍后会在实际测试中引用。我还创建了一个装饰器来做一些日志记录。有没有办法让我可以访问这些self从装饰变量?访问装饰商自我
为了简单起见,我张贴此代码:
def decorator(func):
def _decorator(*args, **kwargs):
# access a from TestSample
func(*args, **kwargs)
return _decorator
class TestSample(unittest.TestCase):
def setUp(self):
self.a = 10
def tearDown(self):
# tear down code
@decorator
def test_a(self):
# testing code goes here
什么是访问一个的最佳方式(在设置中设定())的设计师吗?