Skip to content

Commit 7cf2dbd

Browse files
authored
[Test Proxy] recorded_test compatible with any pytest-asyncio (Azure#28645)
1 parent faa4424 commit 7cf2dbd

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

tools/azure-sdk-tools/devtools_testutils/proxy_fixtures.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@
2626
from typing import Any, Callable, Dict, Optional, Tuple
2727
from pytest import FixtureRequest
2828

29+
# In pytest-asyncio>=0.19.0 async fixtures need to be marked with pytest_asyncio.fixture, not pytest.fixture, by default
30+
# pytest_asyncio.fixture is only recently available (~0.17.0), so we need to account for an import error
31+
try:
32+
from pytest_asyncio import fixture as async_fixture
33+
except ImportError:
34+
from pytest import fixture as async_fixture
35+
2936

3037
_LOGGER = logging.getLogger()
3138

@@ -115,7 +122,7 @@ def environment_variables(test_proxy: None) -> EnvironmentVariableSanitizer:
115122
return EnvironmentVariableSanitizer()
116123

117124

118-
@pytest.fixture
125+
@async_fixture
119126
async def recorded_test(test_proxy: None, request: "FixtureRequest") -> "Dict[str, Any]":
120127
"""Fixture that redirects network requests to target the azure-sdk-tools test proxy.
121128

0 commit comments

Comments
 (0)