![](/img/trans.png)
[英]TypeError: super() argument 1 must be type, not int (Python)
[英]TypeError: super() argument 1 must be type, not MagicMock - azure-devops python package
我正在使用 azure-devOps python 模塊來訪問 azure API 以檢索一些信息。 我使用下面的代碼來設置建立連接所需的身份驗證。
def retrieve_projects_from_organization(self):
credentials = BasicAuthentication('', AZURE_PRIVATE_TOKEN)
self.azure_connection = Connection(base_url=os.environ.get('AZURE_BASE_URL',''),creds=credentials)
core_client = self.azure_connection.clients_v6_0.get_core_client()
project_list = []
projects_response = core_client.get_projects()
while projects_response is not None:
for project in projects_response:
project_list.append(project)
在編寫單元測試用例時,我無法模擬 Connection class,因為它需要 BasicAuthentication 類型的 object。 下面是我的單元測試用例:
def test_retrieve_projects_from_organization(mocker):
credentials = mocker.patch('msrest.authentication. BasicAuthentication')).return_value
connection = mocker.patch('azure.devops.connection.Connection').return_value
core_client = mocker.patch('azure.devops.v6_0.core.CoreClient').return_value
projects = mocker.patch('azure.devops.v6_0.core.TeamProjectReference').return_value
connection._creds = type(credentials)
connection.clients_v6_0.get_core_client.return_value = core_client
core_client.get_projects.return_value = [projects]
assert AzureDataFetcher().retrieve_projects_from_organization() == [projects]
我收到以下錯誤:
TypeError: super() 參數 1 必須是類型,而不是 MagicMock
是否有其他方法可以模擬此 class 或繞過對 API 的身份驗證的方法。
我認為這與您指定模擬的方式有關。 我在這里遇到了同樣的問題。
而不是mocker.patch('msrest.authentication.BasicAuthentication')
嘗試mocker.patch('your_module.BasicAuthentication')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.