@@ -181,6 +181,13 @@ Live Azure resources will be necessary in order to run live tests and produce re
181
181
resource management commands, documented in [ /eng/common/TestResources] [ test_resources ] , that streamline this process.
182
182
Both pure ARM templates (` test-resources.json ` ) and BICEP files (` test-resources.bicep ` ) are supported.
183
183
184
+ User-based authentication is preferred when using test resources. To enable this:
185
+ - Use the [ ` -UserAuth ` command flag] [ user_auth_flag ] when running the ` New-TestResources ` script.
186
+ - Set the environment variable ` AZURE_TEST_USE_PWSH_AUTH ` to "true" to authenticate with Azure PowerShell, or
187
+ ` AZURE_TEST_USE_CLI_AUTH ` to "true" to authenticate with Azure CLI.
188
+ - Ensure you're logged into the tool you choose -- if
189
+ you used ` New-TestResources.ps1 ` to deploy resources, you'll already have logged in with Azure PowerShell.
190
+
184
191
If you haven't yet set up a ` test-resources ` file for test resource deployment and/or want to use test resources of
185
192
your own, you can just configure credentials to target these resources instead.
186
193
@@ -209,14 +216,20 @@ environment variables necessary to run live tests for the service. After storing
209
216
-- formatted as ` VARIABLE=value ` on separate lines -- your credentials and test configuration variables will be set in
210
217
our environment when running tests.
211
218
219
+ If you used the [ ` -UserAuth ` command flag] [ user_auth_flag ] to deploy test resources, set either
220
+ ` AZURE_TEST_USE_PWSH_AUTH ` or ` AZURE_TEST_USE_CLI_AUTH ` to "true" to authenticate with Azure PowerShell or Azure CLI,
221
+ respectively. If both are set to true, Azure PowerShell will be used.
222
+
212
223
If your service doesn't have a ` test-resources ` file for test deployment, you'll need to set environment variables
213
- for ` AZURE_SUBSCRIPTION_ID ` , ` AZURE_TENANT_ID ` , ` AZURE_CLIENT_ID ` , and ` AZURE_CLIENT_SECRET ` at minimum.
224
+ for authentication at minimum. For user-based authentication, use ` AZURE_TEST_USE_PWSH_AUTH ` or
225
+ ` AZURE_TEST_USE_CLI_AUTH ` as described above.
214
226
227
+ For service principal authentication:
215
228
1 . Set the ` AZURE_SUBSCRIPTION_ID ` variable to your organization's subscription ID. You can find it in the "Overview"
216
229
section of the "Subscriptions" blade in the [ Azure Portal] [ azure_portal ] .
217
230
2 . Define the ` AZURE_TENANT_ID ` , ` AZURE_CLIENT_ID ` , and ` AZURE_CLIENT_SECRET ` of a test service principal. If you do not
218
- have a service principal, use the Azure CLI's [ az ad sp create-for-rbac] [ azure_cli_service_principal ] command (ideally,
219
- using your alias as the service principal's name prefix):
231
+ have a service principal, use the Azure CLI's [ az ad sp create-for-rbac] [ azure_cli_service_principal ] command
232
+ (ideally, using your alias as the service principal's name prefix):
220
233
221
234
```
222
235
az login
@@ -326,7 +339,9 @@ well. To run tests in playback, either set `AZURE_TEST_RUN_LIVE` to "false" or l
326
339
327
340
### Run and record tests
328
341
329
- With the ` AZURE_TEST_RUN_LIVE ` environment variable set to "true", use ` pytest ` to run your test(s) in live mode.
342
+ First, refer to the [ Configure test variables] ( #configure-test-variables ) section to ensure environment variables are
343
+ set for test resources and authentication. With the ` AZURE_TEST_RUN_LIVE ` environment variable set to "true", use
344
+ ` pytest ` to run your test(s) in live mode.
330
345
331
346
```
332
347
(env) azure-sdk-for-python\sdk\my-service\my-package> pytest tests
@@ -339,18 +354,18 @@ Playback test errors most frequently indicate a need for additional sanitizers a
339
354
[ Sanitize secrets] ( #sanitize-secrets ) ). If you encounter any unexpected errors, refer to the
340
355
[ test proxy troubleshooting guide] [ troubleshooting_guide ] .
341
356
342
- At this point there should folder called ` recordings ` inside your package's ` tests ` directory. Each recording in this
343
- folder will be a ` .json ` file that captures the HTTP traffic that was generated while running the test matching the
344
- file's name.
357
+ If tests were recorded for a new library, there should now be a folder called ` recordings ` inside your package's
358
+ ` tests ` directory. Each recording in this folder will be a ` .json ` file that captures the HTTP traffic that was
359
+ generated while running the test matching the file's name.
345
360
346
361
The final step in setting up recordings is to move these files out of the ` azure-sdk-for-python ` and into the
347
362
` azure-sdk-assets ` repository. The [ recording migration guide] [ recording_move ] describes how to do so. This step only
348
- needs to be completed once. Your library will have an ` assets.json ` file at its root, which stores the ` azure-sdk-assets `
349
- tag that contains the current set of recordings.
363
+ needs to be completed once. Your library will have an ` assets.json ` file at its root, which stores the
364
+ ` azure-sdk-assets ` tag that contains the current set of recordings.
350
365
351
- From this point on, recordings will automatically be fetched when tests are run in playback mode -- either from
352
- a local cache (described in [ Update test recordings] ( #update-test-recordings ) ), or from ` azure-sdk-assets ` if they're
353
- not locally available.
366
+ From this point on, recordings will automatically be fetched when tests are run in playback mode -- either from a local
367
+ cache (described in [ Update test recordings] ( #update-test-recordings ) ), or from ` azure-sdk-assets ` if they're not
368
+ locally available.
354
369
355
370
#### Update test recordings
356
371
@@ -725,3 +740,4 @@ Tests that use the Shared Access Signature (SAS) to authenticate a client should
725
740
[ test_proxy_startup ] : https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/test_proxy_migration_guide.md#start-the-proxy-server
726
741
[ test_resources ] : https://github.com/Azure/azure-sdk-for-python/tree/main/eng/common/TestResources#readme
727
742
[ troubleshooting_guide ] : https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/test_proxy_troubleshooting.md
743
+ [ user_auth_flag ] : https://github.com/Azure/azure-sdk-for-python/blob/main/eng/common/TestResources/New-TestResources.ps1.md#-userauth
0 commit comments