|
3 | 3 | # Licensed under the MIT License. See License.txt in the project root for |
4 | 4 | # license information. |
5 | 5 | #-------------------------------------------------------------------------- |
| 6 | +import functools |
6 | 7 | import inspect |
7 | 8 | import os.path |
8 | 9 | import sys |
|
20 | 21 | AuthenticationMetadataFilter, OAuthRequestResponsesFilter |
21 | 22 | ) |
22 | 23 | from azure_devtools.scenario_tests.config import TestConfig |
| 24 | +from azure_devtools.scenario_tests.utilities import trim_kwargs_from_test_function |
23 | 25 |
|
24 | 26 | from .config import TEST_SETTING_FILENAME |
25 | 27 | from . import mgmt_settings_fake as fake_settings |
@@ -262,3 +264,21 @@ def get_preparer_resource_name(self, prefix): |
262 | 264 | If prefix is a blank string, use the fully qualified test name instead. |
263 | 265 | This is what legacy tests do for resource groups.""" |
264 | 266 | return self.get_resource_name(prefix or self.qualified_test_name.replace('.', '_')) |
| 267 | + |
| 268 | + @staticmethod |
| 269 | + def await_prepared_test(test_fn): |
| 270 | + """Synchronous wrapper for async test methods. Used to avoid making changes |
| 271 | + upstream to AbstractPreparer (which doesn't await the functions it wraps) |
| 272 | + """ |
| 273 | + |
| 274 | + if sys.version_info < (3, 5): |
| 275 | + raise ImportError("Async wrapper is not needed for Python 2.7 code.") |
| 276 | + |
| 277 | + import asyncio |
| 278 | + @functools.wraps(test_fn) |
| 279 | + def run(test_class_instance, *args, **kwargs): |
| 280 | + trim_kwargs_from_test_function(test_fn, kwargs) |
| 281 | + loop = asyncio.get_event_loop() |
| 282 | + return loop.run_until_complete(test_fn(test_class_instance, **kwargs)) |
| 283 | + |
| 284 | + return run |
0 commit comments