@@ -40,7 +40,7 @@ class TestExample(AzureTestCase):
40
40
...
41
41
42
42
@ExamplePreparer ()
43
- def test_example_with_preparer (self ):
43
+ def test_example_with_preparer (self , example_variable , ** kwargs ):
44
44
...
45
45
```
46
46
@@ -60,13 +60,19 @@ class TestExample(AzureRecordedTestCase):
60
60
61
61
@ExamplePreparer ()
62
62
@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" )
64
65
...
65
66
```
66
67
67
68
For async tests, import the ` recorded_by_proxy_async ` decorator from ` devtools_testutils.aio ` and use it in the same
68
69
way as ` recorded_by_proxy ` .
69
70
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
+
70
76
> ** Note:** since AzureRecordedTestCase doesn't inherit from ` unittest.TestCase ` , test class names need to start
71
77
> with "Test" in order to be properly collected by pytest by default. For more information, please refer to
72
78
> [ pytest's documentation] [ pytest_collection ] .
@@ -287,11 +293,6 @@ the example above (note that the method-style `tables_decorator` is used without
287
293
Decorated test methods will have the values of environment variables passed to them as keyword arguments, and these
288
294
values will automatically have sanitizers registered with the test proxy.
289
295
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
-
295
296
### Record test variables
296
297
297
298
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.
414
415
415
416
For more details on proxy startup, please refer to the [ proxy documentation] [ detailed_docs ] .
416
417
418
+
417
419
[ detailed_docs ] : https://github.com/Azure/azure-sdk-tools/tree/main/tools/test-proxy/Azure.Sdk.Tools.TestProxy/README.md
418
420
[ docker_install ] : https://docs.docker.com/get-docker/
419
421
[ docker_start_proxy ] : https://github.com/Azure/azure-sdk-for-python/blob/main/eng/common/testproxy/docker-start-proxy.ps1
422
+
420
423
[ env_var_loader ] : https://github.com/Azure/azure-sdk-for-python/blob/main/tools/azure-sdk-tools/devtools_testutils/envvariable_loader.py
424
+
421
425
[ general_docs ] : https://github.com/Azure/azure-sdk-tools/blob/main/tools/test-proxy/README.md
426
+
422
427
[ 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
+
423
429
[ pipelines_ci ] : https://github.com/Azure/azure-sdk-for-python/blob/5ba894966ed6b0e1ee8d854871f8c2da36a73d79/sdk/eventgrid/ci.yml#L30
424
430
[ pipelines_live ] : https://github.com/Azure/azure-sdk-for-python/blob/e2b5852deaef04752c1323d2ab0958f83b98858f/sdk/textanalytics/tests.yml#L26-L27
425
431
[ proxy_cert_docs ] : https://github.com/Azure/azure-sdk-tools/blob/main/tools/test-proxy/documentation/trusting-cert-per-language.md
426
432
[ py_sanitizers ] : https://github.com/Azure/azure-sdk-for-python/blob/main/tools/azure-sdk-tools/devtools_testutils/sanitizers.py
427
433
[ pytest_collection ] : https://docs.pytest.org/latest/goodpractices.html#test-discovery
428
434
[ pytest_fixtures ] : https://docs.pytest.org/latest/fixture.html#scope-sharing-fixtures-across-classes-modules-packages-or-session
429
435
[ 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
+
430
438
[ rg_preparer ] : https://github.com/Azure/azure-sdk-for-python/blob/main/tools/azure-sdk-tools/devtools_testutils/resource_testcase.py
439
+
431
440
[ 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
432
441
[ start_test_proxy ] : https://github.com/Azure/azure-sdk-for-python/blob/63a35890a0188dfcac094aa7dc1ec7cc730945cd/tools/azure-sdk-tools/devtools_testutils/proxy_docker_startup.py#L111
433
442
[ 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
+
434
444
[ tables_preparers ] : https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/tables/azure-data-tables/tests/preparers.py
435
445
[ test_resources ] : https://github.com/Azure/azure-sdk-for-python/tree/main/eng/common/TestResources#readme
436
446
[ troubleshooting ] : https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/test_proxy_troubleshooting.md
447
+
437
448
[ variables_api ] : https://github.com/Azure/azure-sdk-tools/tree/main/tools/test-proxy/Azure.Sdk.Tools.TestProxy#storing-variables
438
449
[ vcrpy ] : https://vcrpy.readthedocs.io
0 commit comments