Skip to content

Commit e86b4fa

Browse files
authored
[Test Proxy] Update positional parameter guidance (Azure#24790)
1 parent 469c3b1 commit e86b4fa

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

doc/dev/test_proxy_migration_guide.md

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class TestExample(AzureTestCase):
4040
...
4141

4242
@ExamplePreparer()
43-
def test_example_with_preparer(self):
43+
def test_example_with_preparer(self, example_variable, **kwargs):
4444
...
4545
```
4646

@@ -60,13 +60,19 @@ class TestExample(AzureRecordedTestCase):
6060

6161
@ExamplePreparer()
6262
@recorded_by_proxy
63-
def test_example_with_preparer(self):
63+
def test_example_with_preparer(self, **kwargs):
64+
example_variable = kwargs.pop("example_variable")
6465
...
6566
```
6667

6768
For async tests, import the `recorded_by_proxy_async` decorator from `devtools_testutils.aio` and use it in the same
6869
way as `recorded_by_proxy`.
6970

71+
Because test proxy tests use pure `pytest`, any positional parameter in a test method is assumed to be a reference to
72+
a fixture (see `pytest`'s [How to use fixtures][pytest_using_fixtures] documentation). So, arguments that are passed
73+
to a test by a preparer -- for example, `example_variable` in `test_example_with_preparer` above -- should be
74+
accepted via `**kwargs` and popped off at the start of a test.
75+
7076
> **Note:** since AzureRecordedTestCase doesn't inherit from `unittest.TestCase`, test class names need to start
7177
> with "Test" in order to be properly collected by pytest by default. For more information, please refer to
7278
> [pytest's documentation][pytest_collection].
@@ -287,11 +293,6 @@ the example above (note that the method-style `tables_decorator` is used without
287293
Decorated test methods will have the values of environment variables passed to them as keyword arguments, and these
288294
values will automatically have sanitizers registered with the test proxy.
289295

290-
> **Note:** For tests that are decorated by `@recorded_by_proxy` or `@recorded_by_proxy_async`, the keyword arguments
291-
> passed by EnvironmentVariableLoader can be listed as positional arguments instead of using `**kwargs`. However, tests
292-
> without these decorators can only accept arguments through `**kwargs`. It's therefore recommended that you use
293-
> `**kwargs` in all cases so that tests run successfully with or without `@recorded_by_proxy` decorators.
294-
295296
### Record test variables
296297

297298
To run recorded tests successfully when there's an element of non-secret randomness to them, the test proxy provides a
@@ -414,25 +415,35 @@ container if it's not already running.
414415

415416
For more details on proxy startup, please refer to the [proxy documentation][detailed_docs].
416417

418+
417419
[detailed_docs]: https://github.com/Azure/azure-sdk-tools/tree/main/tools/test-proxy/Azure.Sdk.Tools.TestProxy/README.md
418420
[docker_install]: https://docs.docker.com/get-docker/
419421
[docker_start_proxy]: https://github.com/Azure/azure-sdk-for-python/blob/main/eng/common/testproxy/docker-start-proxy.ps1
422+
420423
[env_var_loader]: https://github.com/Azure/azure-sdk-for-python/blob/main/tools/azure-sdk-tools/devtools_testutils/envvariable_loader.py
424+
421425
[general_docs]: https://github.com/Azure/azure-sdk-tools/blob/main/tools/test-proxy/README.md
426+
422427
[mgmt_recorded_test_case]: https://github.com/Azure/azure-sdk-for-python/blob/main/tools/azure-sdk-tools/devtools_testutils/mgmt_recorded_testcase.py
428+
423429
[pipelines_ci]: https://github.com/Azure/azure-sdk-for-python/blob/5ba894966ed6b0e1ee8d854871f8c2da36a73d79/sdk/eventgrid/ci.yml#L30
424430
[pipelines_live]: https://github.com/Azure/azure-sdk-for-python/blob/e2b5852deaef04752c1323d2ab0958f83b98858f/sdk/textanalytics/tests.yml#L26-L27
425431
[proxy_cert_docs]: https://github.com/Azure/azure-sdk-tools/blob/main/tools/test-proxy/documentation/trusting-cert-per-language.md
426432
[py_sanitizers]: https://github.com/Azure/azure-sdk-for-python/blob/main/tools/azure-sdk-tools/devtools_testutils/sanitizers.py
427433
[pytest_collection]: https://docs.pytest.org/latest/goodpractices.html#test-discovery
428434
[pytest_fixtures]: https://docs.pytest.org/latest/fixture.html#scope-sharing-fixtures-across-classes-modules-packages-or-session
429435
[pytest_setup]: https://docs.pytest.org/xunit_setup.html
436+
[pytest_using_fixtures]: https://docs.pytest.org/latest/how-to/fixtures.html#how-to-fixtures
437+
430438
[rg_preparer]: https://github.com/Azure/azure-sdk-for-python/blob/main/tools/azure-sdk-tools/devtools_testutils/resource_testcase.py
439+
431440
[sanitizers]: https://github.com/Azure/azure-sdk-tools/blob/main/tools/test-proxy/Azure.Sdk.Tools.TestProxy/README.md#session-and-test-level-transforms-sanitiziers-and-matchers
432441
[start_test_proxy]: https://github.com/Azure/azure-sdk-for-python/blob/63a35890a0188dfcac094aa7dc1ec7cc730945cd/tools/azure-sdk-tools/devtools_testutils/proxy_docker_startup.py#L111
433442
[stop_test_proxy]: https://github.com/Azure/azure-sdk-for-python/blob/63a35890a0188dfcac094aa7dc1ec7cc730945cd/tools/azure-sdk-tools/devtools_testutils/proxy_docker_startup.py#L149
443+
434444
[tables_preparers]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/tables/azure-data-tables/tests/preparers.py
435445
[test_resources]: https://github.com/Azure/azure-sdk-for-python/tree/main/eng/common/TestResources#readme
436446
[troubleshooting]: https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/test_proxy_troubleshooting.md
447+
437448
[variables_api]: https://github.com/Azure/azure-sdk-tools/tree/main/tools/test-proxy/Azure.Sdk.Tools.TestProxy#storing-variables
438449
[vcrpy]: https://vcrpy.readthedocs.io

0 commit comments

Comments
 (0)