-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Library to easily mock/stub Azure Python SDK methods? #31330
Comments
Thanks for reaching out. Usually we use modk.patch to mock a method. Does this work for you? |
Hi @jinkang23. Thank you for opening this issue and giving us the opportunity to assist. To help our team better understand your issue and the details of your scenario please provide a response to the question asked above or the information requested above. This will help us more accurately address your issue. |
Hi @jinkang23, Here's an example I made for some unit tests in the Tables SDK: As mentioned, all our SDKs support this, so you should be able to share the implementation between any combination of SDKs you might be using. from azure.core.pipeline.transport import HttpTransport
class MockTransport(HttpTransport):
def send(request: HttpRequest, **kwargs) -> HttpResponse:
# This is where you add any test logic, for example, testing a connection failure:
# raise azure.core.exception.ServiceResponseError("something went wrong!")
# Then we can plug this into any SDK via kwargs:
storage_client = BlobServiceClient(account_url, credential, transport=MockTransport()) |
Hi @jinkang23, we're sending this friendly reminder because we haven't heard back from you in 7 days. We need more information about this issue to help address it. Please be sure to give us your input. If we don't hear back from you within 14 days of this comment the issue will be automatically closed. Thank you! |
@annatisch Could you possibly advise on mocking AsyncHttpTransport? I'm having a harder time with that, starting from your code. Current status:
|
Update: My test is passing now, but is very slow (20 seconds), so I'm wondering if the SDK code is waiting/sleeping somewhere. Typically I expected tests with mocked out network calls to be quite fast. |
Are there any library to easily mock and stub Azure Python SDK methods for writing unit tests?
I noticed that azure-devtools project may offer this capability but it has been archived since 2020.
What I'm looking for is similar to Moto library for AWS boto3 SDK but for Azure Python SDK.
Thank you.
The text was updated successfully, but these errors were encountered: