You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -87,13 +90,13 @@ Open the directory for your package in your preferred editor, for example VSCode
87
90
88
91
As a quick background, the Azure SDK uses the [pytest](https://docs.pytest.org/en/latest/) test runner to support creating unit and functional tests for Track 2 Azure libraries. To intall `pytest` run `pip install pytest` from your virtual environment, you can confirm the installation was successful by running `pytest -V`. The commands will run all files of the form `test_*.py` or `*_test.py` in the provided directory and its subdirectories; for more information check out the [docs][pytest_invocation].
89
92
90
-
With the pytest test suite you can provide directories or specific tests to run rather than running the entire test suite:
93
+
With `pytest`you can provide a either a directory or a specific test file to run:
`add_general_regex_sanitizer` accepts a regex, replacement value, and capture group as keyword-only arguments. In the
391
+
snippet above, any storage endpoint URIs that match the specified URI regex will have their account name replaced with
392
+
"fakeendpoint". A request made to `https://tableaccount-secondary.table.core.windows.net` will be recorded as being
393
+
made to `https://fakeendpoint-secondary.table.core.windows.net`, and URIs will also be sanitized in bodies and headers.
394
+
395
+
For more details about sanitizers and their options, please refer to [devtools_testutils/sanitizers.py][py_sanitizers].
396
+
397
+
#### Special case: SAS tokens
398
+
399
+
Tests that use a Shared Access Signature (SAS) token to authenticate a client should use the
400
+
[`AzureRecordedTestCase.generate_sas`][generate_sas] method to generate the token. This will automatically register a
401
+
sanitizer to keep this token out of test recordings. An example of using this method can be found
402
+
[here][generate_sas_example].
403
+
404
+
`generate_sas` accepts any number of positional arguments: the first being the method that creates the SAS, and the
405
+
remaining positional arguments being positional arguments for the SAS-generating method. Any keyword arguments given to
406
+
`generate_sas` will be passed to the SAS-generating method as well. The generated token will be returned and its value
407
+
will be sanitized.
408
+
328
409
## Functional vs. unit tests
329
410
330
411
The tests written above are functional tests: they generate HTTP traffic and send data to the service. For tests that
@@ -383,15 +464,17 @@ class TestTablesUnitTest(object):
383
464
```
384
465
385
466
386
-
## More test examples
467
+
## Further reading
387
468
388
-
This section will demonstrate how to write tests with the `devtools_testutils` package with a few samples to showcase the features of the test framework.
389
-
390
-
For more information, refer to the [advanced tests notes][advanced_tests_notes] on more advanced scenarios and additional information.
469
+
For information about more advanced testing scenarios, refer to the [advanced tests notes][advanced_tests_notes].
391
470
392
471
393
472
## Deprecated testing instructions
394
473
474
+
> The testing framework described in this section was used before today's test proxy was adopted. These instructions are
475
+
> deprecated and shouldn't be used to write new tests, but may be helpful in understanding and working with test suites
476
+
> that haven't migrated to the new system.
477
+
395
478
Older SDK tests are based on the `scenario_tests` subpackage located in [`azure-sdk-for-python/tools/azure-devtools/src/azure_devtools`](https://pypi.org/project/azure-devtools/). `scenario_tests` is a general, mostly abstracted framework which provides several useful features for writing SDK tests, ie:
396
479
* HTTP interaction recording and playback using [vcrpy](https://pypi.python.org/pypi/vcrpy)
397
480
* Creation and cleanup of helper resources, such as resource groups, storage accounts, etc. which can be used in order to test services
@@ -556,6 +639,9 @@ Tests that use the Shared Access Signature (SAS) to authenticate a client should
0 commit comments