Skip to content

Contributor Guide

hallvictoria edited this page Jun 30, 2025 · 2 revisions

This page explains how to set up the development environment and run tests locally.

Prerequisites

You need to have the following installed on your system:

  1. Python 3.10.x+
  2. dotnet 6.x+
  3. azure-functions-core-tools <https://github.com/Azure/azure-functions-core-tools>_
  4. Export CORE_TOOLS_EXE_PATH to the installation path Azure Functions Core Tools <https://github.com/Azure/azure-functions-core-tools>_ (e.g. on macOS as installed by brew - /usr/local/bin/func)

Setting up a development environment

Note: On macOS systems, where zsh is used, you might see some issues. In the meantime, please use bash to run these commands.

  1. Clone the repository:
git clone https://github.com/Azure/azure-functions-python-worker.git
  1. Create a virtual environment:
python -m venv worker_env
  1. Activate the virtual environment:
source worker_env/bin/activate
  1. Change the directory to the root of the cloned repository:
cd azure-functions-python-worker
  1. Download pyproject.toml optional-dependencies dev packages:
pip install .[dev]
  1. Build gRPC message, download WebHost binaries, and build Azure Functions extensions:
cd tests
invoke -c test_setup build-protos
invoke -c test_setup webhost
invoke -c test_setup extensions
  1. Create a test function app, obtain the AzureWebJobsStorage key, and various service connection strings and put them into .testconfig (no quotes on around ConnectionStrings):
[azure]
storage_key = DefaultEndpointsProtocol=https;...
cosmosdb_key = AccountEndpoint=https://endpoint.documents.azure.com:443/;...
eventhub_key = Endpoint=sb://endpoint.servicebus.windows.net/;...
servicebus_key = Endpoint=sb://endpoint.servicebus.windows.net/;...
eventgrid_topic_uri = https://eventgridendpoint.region.eventgrid.azure.net/api/events
eventgrid_topic_key = event_grid_key

Running tests

  1. Activate the dev virtual environment:
source worker_env/bin/activate
  1. Change the directory to the root of the cloned repository:
cd azure-functions-python-worker
  1. Run tests with pytest:
# test everything
pytest
# test specifc file : pytest <test.py file location>
pytest tests/unittests/test_mock_eventhub_functions.py
# test specific method : pytest <test.py file location>::<test class>::<test method>
pytest tests/unittests/test_mock_eventhub_functions.py::TestEventHubMockFunctions::test_mock_eventhub_cardinality_one

Running a web host to call test functions

  1. Activate the dev virtual environment:
source worker_env/bin/activate
  1. Change the directory to the root of the cloned repository:
cd azure-functions-python-worker
  1. Start a local webhost:
python -m azure.worker.testutils <directory-with-python-functions>

Testing with alternative Functions WebHost

Alternatively, download/build manually and then specify the full path to Microsoft.Azure.WebJobs.Script.WebHost.dll either in the PYAZURE_WEBHOST_PATH environment variable, or in the .testconfig (no quotes on around dll path) configuration file:

[webhost]
dll = <path to Microsoft.Azure.WebJobs.Script.WebHost.dll>

Building docs

  1. Activate the dev virtual environment:
source worker_env/bin/activate
  1. Change the directory to the root of the cloned repository / docs:
cd azure-functions-python-worker/docs
  1. Ensure that sphinx package is installed:
pip install sphinx
  1. Build the docs!
make html

Project Structure Overview

workers: this directory holds the Python worker that's shipped as part of the host runtime

  • azure_functions_worker: host-worker contract and execution logic for Python 3.7 - 3.12
  • proxy_worker: host-worker contract ONLY for Python 3.13+

azure_functions_worker_v1: this directory contains the azure-functions-runtime-v1 library code

  • azure_functions_worker_v1: worker execution logic ONLY for the V1 programming model for Python 3.13+

azure_functions_worker_v2: this directory contains the azure-functions-runtime library code

  • azure_functions_worker_v2: worker execution logic ONLY for the V2 programming model for Python 3.13+

Please refer to the Pull Request Checklist for more information on where to add changes. Mention one of the CODEOWNERS if further clarification is needed.

Clone this wiki locally