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

[TestProxy] Variables should not require "is_live" awareness #22275

Closed
tjprescott opened this issue Dec 29, 2021 · 1 comment
Closed

[TestProxy] Variables should not require "is_live" awareness #22275

tjprescott opened this issue Dec 29, 2021 · 1 comment
Assignees

Comments

@tjprescott
Copy link
Member

https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/test_proxy_migration_guide.md#record-test-variables

Currently, in order to have a "variables" collection, you need to specify it in the signature and return it from the test method. This means that your test method body has to be aware of whether the test is being run live or not. The test author should not have to have conditional "live" checks as this will bloat the test and make it more difficult to reason about.

It would be preferable if the test author could handle variables in a decorator, preparer, fixture, etc, similar to the woefully misnamed PowerShellPreparer. That preparer handles environment variables. If present, it uses those values--otherwise it uses a static value.

A VariablesPreparer would function similarly:

  • if the test is being played back, it will load the value for the recording's "variables" collection
  • if the test is running live, it will generate a random value and store it in the variables collection for playback

For each item in the VariabesPreparer, the author should be able to specify a prefix, if desired, for easier debugging. Using a preparer might also negate the need to modify the test body to return the variables collection, as the variables will not (and should not!) be manipulated in the test method body.

@mccoyp
Copy link
Member

mccoyp commented Sep 28, 2022

This is now addressed with the recommended use of the built-in setdefault dictionary method when using @recorded_by_proxy(_async) decorators, and with the variable_recorder fixture when using the recorded_test fixture.

@mccoyp mccoyp closed this as completed Sep 28, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Apr 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants