-
Notifications
You must be signed in to change notification settings - Fork 322
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
33 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,33 @@ | ||
wip | ||
# Azure Functions Tests | ||
|
||
The functional tests for Azure Functions do not run the Azure functions locally, but instead invoke the entrypoints of the Python functions directly within each test. | ||
|
||
For example, consider the following: | ||
|
||
```py | ||
import azure.functions as func | ||
|
||
app = func.FunctionApp() | ||
|
||
@app.function_name(name="HttpTrigger1") | ||
@app.route(route="req") | ||
def main(req): | ||
user = req.params.get("user") | ||
return f"Hello, {user}!" | ||
``` | ||
|
||
Instead of making an HTTP request to `/api/req` from within a test, import the function directly and call the function with a payload similar to what would be | ||
expected when running in Azure. | ||
|
||
|
||
```py | ||
req = func.HttpRequest( | ||
method="GET", | ||
url="http://localhost:7071/api/req", | ||
body=b"", | ||
) | ||
|
||
main.build().get_user_function()(req) | ||
``` | ||
|
||
Downstream dependcies are mocked using [pytest-httpserver](https://pytest-httpserver.readthedocs.io/). |