我在基类中有以下装饰器:
class BaseTests(TestCase):
@staticmethod
def check_time(self, fn):
@wraps(fn)
def test_wrapper(*args,**kwargs):
# do checks ...
return test_wrapper
Run Code Online (Sandbox Code Playgroud)
以下类继承自BaseTests:
from path.base_posting import BaseTests
from path.base_posting.BaseTests import check_time # THIS LINE DOES NOT WORK!
class SpecificTest(BaseTests):
@check_time # use the decorator
def test_post(self):
# do testing ...
Run Code Online (Sandbox Code Playgroud)
我想在上面的SpecificTest中使用装饰器,而不必使用BaseTests.check_time,因为在原始代码中他们有很长的名字,我必须在很多地方使用它.有任何想法吗?
编辑:我决定让check_time成为BaseTests文件中的一个独立函数,并简单地导入
from path.base_posting import BaseTests, check_time
Run Code Online (Sandbox Code Playgroud) 我基本上会执行转储和加载的序列,但是在某些时候我想删除已加载的条目之一。我怎样才能做到这一点?有没有办法删除或编辑用Python pickle / pickckle保存的条目?
编辑:数据用pickle保存在一个二进制文件中。