Skip to content

Contributor Guide

wangbill edited this page Apr 4, 2024 · 12 revisions

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

You need to have the following installed on your system:

  1. Python 3.6.x+
  2. dotnetcore-sdk 2.x
  3. azure-functions-core-tools 2.x/3.x
  4. Export CORE_TOOLS_EXE_PATH to the installation path Azure Functions Core Tools (e.g. on macOS as installed by brew - /usr/local/bin/func)

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:
python3.6 -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 setup.py extras_require dev packages:
pip install -U -e .[dev]
  1. Build gRPC message, download WebHost binaries, and build Azure Functions extensions defined in setup.py:
python setup.py develop
python setup.py build
python setup.py webhost
python setup.py extension
  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
  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
  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>

Currently, the WebHost dependency is specified as an Appveyor artifact url in WEBHOST_URL in setup.py.

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>
  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