Skip to content

Commit 34795f5

Browse files
authored
Clearer guidance on test credential usage (#35499)
1 parent 65e5a32 commit 34795f5

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

doc/dev/tests.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,6 @@ testing infrastructure, and demonstrates how to write and run tests for a servic
2626
- [Special case: SAS tokens](#special-case-sas-tokens)
2727
- [Functional vs. unit tests](#functional-vs-unit-tests)
2828
- [Further reading](#further-reading)
29-
- [Deprecated testing instructions](#deprecated-testing-instructions)
30-
- [Define credentials (deprecated)](#define-credentials-deprecated)
31-
- [Create live test resources (deprecated)](#create-live-test-resources-deprecated)
32-
- [Write your tests (deprecated)](#write-your-tests-deprecated)
33-
- [An example test (deprecated)](#an-example-test-deprecated)
34-
- [Run and record the test (deprecated)](#run-and-record-the-test-deprecated)
35-
- [Purging secrets (deprecated)](#purging-secrets-deprecated)
36-
- [Special case: Shared Access Signature (deprecated)](#special-case-shared-access-signature-deprecated)
3729

3830
## Set up your development environment
3931

@@ -191,6 +183,9 @@ User-based authentication is preferred when using test resources. To enable this
191183
- Ensure you're logged into the tool you choose -- if
192184
you used `New-TestResources.ps1` to deploy resources, you'll already have logged in with Azure PowerShell.
193185

186+
**Important:** these environment variables will only be successfully used if test credentials are fetched with the
187+
[`AzureRecordedTestCase.get_credential`][get_credential] method. See [Write your tests](#write-your-tests) for details.
188+
194189
If you haven't yet set up a `test-resources` file for test resource deployment and/or want to use test resources of
195190
your own, you can just configure credentials to target these resources instead.
196191

@@ -226,6 +221,9 @@ authenticate with by setting an `AZURE_TEST_USE_*_AUTH` environment variable to
226221
3. Visual Studio Code: set `AZURE_TEST_USE_VSCODE_AUTH`.
227222
4. Azure Developer CLI (`azd`): set `AZURE_TEST_USE_AZD_AUTH`.
228223

224+
**Important:** these environment variables will only be successfully used if test credentials are fetched with the
225+
[`AzureRecordedTestCase.get_credential`][get_credential] method. See [Write your tests](#write-your-tests) for details.
226+
229227
If your service doesn't have a `test-resources` file for test deployment, you'll need to set environment variables
230228
for authentication at minimum. For user-based authentication, use `AZURE_TEST_USE_*_AUTH` as described above.
231229

@@ -327,6 +325,9 @@ AzureRecordedTestCase, EnvironmentVariableLoader, recorded_by_proxy`.
327325
- The signature of your test method will always contain `self`, and following `self` will be all the keys that you
328326
need from your preparer. A test does not need to accept every key from the preparer; the test framework will only pass
329327
in the parameters specifically requested in the test method signature.
328+
- Fetch a credential for your service client with [`self.get_credential`][get_credential]. This is necessary for the
329+
credential to be usable in playback tests, and for it to make use of the authentication method selected by
330+
`AZURE_TEST_USE_*_AUTH` environment variables.
330331
- Within tests, use the `assert` keyword to assert conditions that you expect to be true.
331332

332333
If you need logging functionality for your testing, pytest also offers [logging][pytest_logging] capabilities either
@@ -561,6 +562,7 @@ For information about more advanced testing scenarios, refer to the [advanced te
561562
[env_var_loader]: https://github.com/Azure/azure-sdk-for-python/blob/main/tools/azure-sdk-tools/devtools_testutils/envvariable_loader.py
562563
[generate_sas]: https://github.com/Azure/azure-sdk-for-python/blob/bf4749babb363e2dc972775f4408036e31f361b4/tools/azure-sdk-tools/devtools_testutils/azure_recorded_testcase.py#L196
563564
[generate_sas_example]: https://github.com/Azure/azure-sdk-for-python/blob/3e3fbe818eb3c80ffdf6f9f1a86affd7e879b6ce/sdk/tables/azure-data-tables/tests/test_table_entity.py#L1691
565+
[get_credential]: https://github.com/Azure/azure-sdk-for-python/blob/20cf5b0bd9b87f90bd5ad4fd36358d3b257f95c5/tools/azure-sdk-tools/devtools_testutils/azure_recorded_testcase.py#L96
564566
[git_setup]: https://git-scm.com/book/en/v2/Getting-Started-First-Time-Git-Setup
565567
[kv_test_resources]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/keyvault/test-resources.json
566568
[kv_test_resources_outputs]: https://github.com/Azure/azure-sdk-for-python/blob/fbdb860630bcc13c1e355828231161849a9bd5a4/sdk/keyvault/test-resources.json#L255

0 commit comments

Comments
 (0)