在unittest的setUp()方法中,我设置了一些自变量,稍后在实际测试中引用.我还创建了一个装饰器来做一些日志记录.有没有办法可以从装饰器访问这些自变量?
为简单起见,我发布此代码:
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
Run Code Online (Sandbox Code Playgroud)
什么是访问的最好办法一个从装饰(()在设置中设定)?