2017-07-03 86 views
0

有沒有一種方法來捕捉,而不必模擬傳遞到函數中patch裝飾以下邏輯:配置返回值的模擬與裝飾只有

@patch('boto3.client') 
def test_playing_with_saml(self, boto3_client): 
    boto3_client.return_value.assume_role_with_saml = lambda *args, **kwargs: ('foo', 'bar') 
    self.assertEqual(playing_with_saml(), 'expected') 

回答

1

不,不是真的,不是沒有speccing出其餘的boto3_client,這是而不是將變得更清晰或更具可讀性。

我不使用lambda在這裏,你可以設置模擬的返回值來代替:

boto3_client.return_value.assume_role_with_saml.return_value = ('foo', 'bar') 

現在你可以做出關於boto3_client.return_value.assume_role_with_saml方法斷言(如聲稱它已被調用)。

+0

我不知道你可以像這樣鏈接它!乾杯。 – RNikoopour