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] Improve variables API documentation #25203

Merged
merged 1 commit into from
Jul 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Update variables documentation
  • Loading branch information
mccoyp authored Jul 13, 2022
commit 711f069aa122f45009176a495af4723ac00adace
19 changes: 12 additions & 7 deletions doc/dev/test_proxy_migration_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -316,20 +316,25 @@ class TestExample(AzureRecordedTestCase):

@recorded_by_proxy
def test_example(self, **kwargs):
# in live mode, variables is an empty dictionary
# in playback mode, the value of variables is {"table_name": "random-value"}
variables = kwargs.pop("variables")
if self.is_live:
table_name = "random-value"
variables = {"table_name": table_name}
# In live mode, variables is an empty dictionary
# In playback mode, the value of variables is {"table_name": "random-value"}
variables = kwargs.pop("variables", {})

# To fetch variable values, use the `setdefault` method to look for a key ("table_name")
# and set a real value for that key if it's not present ("random-value")
table_name = variables.setdefault("table_name", "random-value")

# use variables["table_name"] when using the table name throughout the test
...

# return the variables at the end of the test
# return the variables at the end of the test to record them
return variables
```

> **Note:** `variables` will be passed as a named argument to any test that accepts `kwargs` by the test proxy. In
> environments that don't use the test proxy, though -- like live test pipelines -- `variables` won't be provided.
> To avoid a KeyError, providing an empty dictionary as the default value to `kwargs.pop` is recommended.

## Migrate management-plane tests

For management-plane packages, test classes should inherit from [AzureMgmtRecordedTestCase][mgmt_recorded_test_case]
Expand Down