Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 初始化类中的记录器以在重试装饰器中使用_Python_Unit Testing_Mocking_Decorator - Fatal编程技术网

Python 初始化类中的记录器以在重试装饰器中使用

Python 初始化类中的记录器以在重试装饰器中使用,python,unit-testing,mocking,decorator,Python,Unit Testing,Mocking,Decorator,我正在编写数据库客户端,我希望在重试装饰器中使用特定的记录器: 将熊猫作为pd导入 从重试导入重试 从SetUp.SetUp导入SetUp日志,SetUp环境,获取重试参数 DBClient类: 定义初始化(自): self.log=set_logging() self.connection=设置环境() self.tries,self.delay=get\u retry\u参数() @重试(尝试=尝试,延迟=延迟,记录器=日志) def get_艺术家_表(自身): 是否可以使用我在retr

我正在编写数据库客户端,我希望在重试装饰器中使用特定的记录器:

将熊猫作为pd导入
从重试导入重试
从SetUp.SetUp导入SetUp日志,SetUp环境,获取重试参数
DBClient类:
定义初始化(自):
self.log=set_logging()
self.connection=设置环境()
self.tries,self.delay=get\u retry\u参数()
@重试(尝试=尝试,延迟=延迟,记录器=日志)
def get_艺术家_表(自身):

是否可以使用我在retry decorator(它是一个外部库)中实例化类的变量。

使用retry\u调用而不是retry。这应该足以满足您的要求


非常感谢你,这就像一个符咒,我只是不能裹住我的头,但你救了我!
import pandas as pd
from set_up.SetUp import set_logging, set_up_environment, get_retry_parameters
from retry.api import retry_call

def retrydecorator(func):
    def inner(self, *fargs, **fkwargs):
        result = retry_call(func, fargs=(self,)+fargs, fkwargs=fkwargs, tries=self.tries, delay=self.delay, logger=self.log)
        return result
    return inner

class DBClient:
    def __init__(self):
        self.log = set_logging()
        self.connection = set_up_environment()
        self.tries,self.delay = get_retry_parameters()

    @retrydecorator
    def get_artist_table(self):
        pass