Skip to content

[TestProxy] Run test with testproxy for mgmt SDK

Yuchao Yan edited this page Feb 24, 2022 · 13 revisions

Getting Started - Run test with testproxy for mgmt SDK

Prerequisites

  • Python 3.7 or later is required

  • install Docker

  • create virtual environment

    python -m venv venv
    .\venv-dev\Scripts\Activate.ps1
    
  • prepare SDK repo if needed

    git clone https://github.com/Azure/azure-sdk-for-python.git
    
  • prepare Docker with TestProxy if needed. (more details)

    Run the following command to download and run the docker image with Testproxy.(Note: the first running of this command will download docker. And in the future, the test results will be recorded in the service under this path)

    cd D:\azure-sdk-for-python
    .\eng\common\testproxy\docker-start-proxy.ps1 "start"
    

How to Run Test

  • Setting environment variables (Powershell)

    run following command

    $env:AZURE_TENANT_ID="xxxxxxxxxxxxxxxx"
    $env:AZURE_CLIENT_ID="xxxxxxxxxxxxxxxx"
    $env:AZURE_CLIENT_SECRET="xxxxxxxxxxxxxxxx"
    $env:AZURE_SUBSCRIPTION_ID="xxxxxxxxxxxxxxxx"
    
  • Setting the necessary configuration

    1. Copy mgmt_settings_real_.py to tools\azure-sdk-tools\devtools_testutils and rename it to mgmt_settings_real.py

    2. Replace the ENV_SUBSCRIPTION_ID, ENV_CLIENT_ID, ENV_CLIENT_SECRET, ENV_TENANT_ID with available values in this file. (Note: some values appear multiple times and need to be replaced completely)

  • Preparation dependence

    Go to the directory for test. Like this: D:\azure-sdk-for-python\sdk\servicebus\azure-mgmt-servicebus

    And run command:

    pip install -r dev_requirements.txt
    pip install -e .
    
  • Add test proxy certificate (just need for the first time)

    Copy content of certificate to the end of cacert.pem in venv\Lib\site-packages\certifi\

  • Then run test command like:

    (venv) D:\azure-sdk-for-python\sdk\servicebus\azure-mgmt-servicebus>pytest tests
    
  • Check the test results MicrosoftTeams-image (4)

  • Complete migration guide

    FYR: https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/test_proxy_migration_guide.md#guide-for-migrating-to-the-test-proxy-from-vcrpy

Clone this wiki locally