Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Test Proxy] Add fixture to automatically start/stop Docker container #21538

Merged
merged 5 commits into from
Nov 10, 2021

Conversation

mccoyp
Copy link
Member

@mccoyp mccoyp commented Nov 2, 2021

This adds a session-level fixture, test_proxy, that can be used to start the proxy Docker container before recorded tests run and shut it down after all tests in the pytest session are run. It also exposes two helper methods used by the fixture, start_test_proxy and stop_test_proxy, that can be called directly to manually start or stop the proxy container.

The container needs some time to warm up before it'll accept incoming requests, so the start_test_proxy method pings a proxy endpoint with GET requests until receiving a 200 (or until a 10-minute timeout is hit).

Usage example (that will be added to the migration guide soon)
In a package's conftest.py, make the fixture name a parameter to any proxy-dependent, session-level fixtures:

import os
from devtools_testutils import add_general_regex_sanitizer, test_proxy

@pytest.fixture(scope="session", autouse=True)
def sanitize_account_name(test_proxy):
    add_general_regex_sanitizer(value="fakeendpoint", regex=os.envrion["TABLES_STORAGE_ACCOUNT_NAME"])

This will make sure the the container startup script is run before any sanitizers are registered (otherwise, we'd get errors). If no sanitizers are being registered with session-level fixtures, a dummy fixture can be added to the package's conftest.py instead, that just invokes the test_proxy fixture:

from devtools_testutils import test_proxy

@pytest.fixture(scope="session", autouse=True)
def start_proxy(test_proxy):
    return

@mccoyp mccoyp requested review from YalinLi0312 and scbedd November 3, 2021 01:03
Copy link
Member

@scbedd scbedd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to handle PROXY_MANUAL_START here. Once we do that this is good to merge.

@mccoyp mccoyp merged commit d3ee41d into Azure:main Nov 10, 2021
@mccoyp mccoyp deleted the proxy-docker-start branch November 10, 2021 02:26
iscai-msft added a commit to iscai-msft/azure-sdk-for-python that referenced this pull request Nov 10, 2021
…into add_webpubsub_tests

* 'main' of https://github.com/Azure/azure-sdk-for-python:
  [Key Vault] Add support for multi-tenant authentication (Azure#21290)
  [webpubsub] regen with hub as a client parameter (Azure#21688)
  update automatic close mechanism (Azure#21580)
  [Test Proxy] Add fixture to automatically start/stop Docker container (Azure#21538)
  Update Monitor Query API ref link (Azure#21683)
  Migration Guide from Azure-loganalytics (Azure#21674)
  Update docs for Web PubSub GA (Azure#21659)
  Update CHANGELOG.md (Azure#21681)
  Increment version for formrecognizer releases (Azure#21678)
  Increment version for videoanalyzer releases (Azure#21455)
  Increment version for cognitivelanguage releases (Azure#21566)
  Increment version for storage releases (Azure#21652)
  Increment version for communication releases (Azure#21667)
  raise decode error instead of ContentDecodingError (Azure#19433)
  Update CHANGELOG.md (Azure#21679)
  resolve mac agent failure (Azure#21677)
  Re-add get-codeowners.ps1 (Azure#21676)
  [SchemaRegistry] remove schema prefix in params (Azure#21675)
  Validate python docs packages using docker (Azure#21657)
  update git helper (Azure#21670)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants