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
什麼是訪問一個的最佳方式(在設置中設定())的設計師嗎?