Skip to content

Commit af58385

Browse files
committed
Acrolynx improvements and PR suggestions
1 parent 027155c commit af58385

File tree

4 files changed

+13
-11
lines changed

4 files changed

+13
-11
lines changed

articles/azure-functions/durable/durable-functions-unit-testing-python.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ ms.author: azfuncdf
99

1010
# Unit Testing Durable Functions in Python
1111

12-
Unit testing is an important part of modern software development practices. Unit tests verify business logic behavior and protect from introducing unnoticed breaking changes in the future. Durable Functions can easily grow in complexity so introducing unit tests will help to avoid breaking changes. The following sections explain how to unit test the three function types - Orchestration client, orchestrator, and entity functions.
12+
Unit testing is an important part of modern software development practices. Unit tests verify business logic behavior and protect from introducing unnoticed breaking changes in the future. Durable Functions can easily grow in complexity so introducing unit tests helps avoid breaking changes. The following sections explain how to unit test the three function types - Orchestration client, orchestrator, and entity functions.
1313

1414
> [!NOTE]
1515
> This guide applies only to Durable Functions apps written in the [Python v2 programming model](../functions-reference-python.md).
@@ -25,15 +25,15 @@ The examples in this article require knowledge of the following concepts and fra
2525

2626
## Setting Up the Test Environment
2727

28-
To test Durable Functions, it's crucial to set up a proper test environment. This includes creating a test directory and installing unittest into your Python environment. For more info, see the [Azure Functions Python unit testing overview](../functions-reference-python.md#unit-testing).
28+
To test Durable Functions, it's crucial to set up a proper test environment. This includes creating a test directory and installing Python's `unittest` module into your Python environment. For more info, see the [Azure Functions Python unit testing overview](../functions-reference-python.md#unit-testing).
2929

3030
## Unit testing trigger functions
3131

3232
Trigger functions, often referred to as _client_ functions, initiate orchestrations and external events. To test these functions:
3333

3434
- Mock the `DurableOrchestrationClient` to simulate orchestration execution and status management.
3535
- Assign `DurableOrchestrationClient` methods such as `start_new`, `get_status`, or `raise_event` with mock functions that return expected values.
36-
- Invoke the client function directly with a mocked client as well as other necessary inputs such as a `req` (HTTP request object) for HTTP trigger client functions.
36+
- Invoke the client function directly with a mocked client and other necessary inputs such as a `req` (HTTP request object) for HTTP trigger client functions.
3737
- Use assertions and `unittest.mock` tools to verify expected orchestration start behavior, parameters, and HTTP responses.
3838

3939
```python
@@ -71,9 +71,9 @@ class TestFunction(unittest.TestCase):
7171
Orchestrator functions manage the execution of multiple activity functions. To test an orchestrator:
7272

7373
- Mock the `DurableOrchestrationContext` to control function execution.
74-
- Replace `DurableOrchestrationContext` methods needed for orchestrator execution like `call_activity` or `create_timer` with mock functions. These functions should have pre-determined behavior and should typically return Task objects with a `result` property.
75-
- Call the orchestrator recursively, passing the result of the Task generated by the previous yield statement to the next.
76-
- Use the results returned from the orchestrator, as well as `unittest.mock` methods to verify the orchestrator result.
74+
- Replace `DurableOrchestrationContext` methods needed for orchestrator execution like `call_activity` or `create_timer` with mock functions. These functions will typically return objects of type TaskBase with a `result` property.
75+
- Call the orchestrator recursively, passing the result of the Task generated by the previous yield statement to the next.
76+
- Verify the orchestrator result using the results returned from the orchestrator and `unittest.mock`.
7777

7878
```python
7979
import unittest
@@ -90,6 +90,8 @@ class TestFunction(unittest.TestCase):
9090
# Get the original method definition as seen in the function_app.py file
9191
func_call = my_orchestrator.build().get_user_function().orchestrator_function
9292

93+
# The mock_activity method is defined above with behavior specific to your app.
94+
# It returns a TaskBase object with the result expected from the activity call.
9395
context.call_activity = Mock(side_effect=mock_activity)
9496

9597
# Create a generator using the method and mocked context

articles/azure-functions/durable/durable-functions-unit-testing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ ms.date: 11/03/2019
77

88
# Durable Functions unit testing (C#)
99

10-
Unit testing is an important part of modern software development practices. Unit tests verify business logic behavior and protect from introducing unnoticed breaking changes in the future. Durable Functions can easily grow in complexity so introducing unit tests will help to avoid breaking changes. The following sections explain how to unit test the three function types - Orchestration client, orchestrator, and activity functions.
10+
Unit testing is an important part of modern software development practices. Unit tests verify business logic behavior and protect from introducing unnoticed breaking changes in the future. Durable Functions can easily grow in complexity so introducing unit tests helps avoid breaking changes. The following sections explain how to unit test the three function types - Orchestration client, orchestrator, and activity functions.
1111

1212
> [!NOTE]
1313
> This article provides guidance for unit testing for Durable Functions apps written in C# for the .NET in-process worker and targeting Durable Functions 2.x. For more information about the differences between versions, see the [Durable Functions versions](durable-functions-versions.md) article.

articles/azure-functions/durable/quickstart-python-vscode.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -379,10 +379,6 @@ After you verify that the function runs correctly on your local computer, it's t
379379

380380
[!INCLUDE [functions-publish-project-vscode](../../../includes/functions-publish-project-vscode.md)]
381381

382-
## Unit testing
383-
384-
For more information on unit testing functions in Python, see our [Python unit testing guide](durable-functions-unit-testing-python.md)
385-
386382
## Test your function in Azure
387383

388384
::: zone pivot="python-mode-configuration"
@@ -412,3 +408,4 @@ If you no longer need the resources that you created to complete the quickstart,
412408
## Related content
413409

414410
* Learn about [common Durable Functions app patterns](durable-functions-overview.md#application-patterns).
411+
* Learn about [Unit Testing Durable Functions in Python](durable-functions-unit-testing-python.md)

articles/azure-functions/functions-reference-python.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1427,6 +1427,9 @@ class TestFunction(unittest.TestCase):
14271427

14281428
Inside your *.venv* Python virtual environment folder, install your favorite Python test framework, such as `pip install pytest`. Then run `pytest tests` to check the test result.
14291429

1430+
> [!NOTE]
1431+
> Durable Functions require special syntax for unit testing. For more information, refer to [Unit Testing Durable Functions in Python](durable-functions-unit-testing-python.md)
1432+
14301433
::: zone-end
14311434

14321435
## Temporary files

0 commit comments

Comments
 (0)