@@ -113,7 +113,7 @@ def environment_variables(test_proxy: None) -> EnvironmentVariableSanitizer:
113113
114114
115115@pytest .fixture
116- async def recorded_test (test_proxy : None , request : "FixtureRequest" ) -> "Dict[str, Any]" :
116+ async def recorded_test (test_proxy : None , request : "FixtureRequest" ) -> "Optional[ Dict[str, Any] ]" :
117117 """Fixture that redirects network requests to target the azure-sdk-tools test proxy.
118118
119119 Use with recorded tests. For more details and usage examples, refer to
@@ -125,21 +125,24 @@ async def recorded_test(test_proxy: None, request: "FixtureRequest") -> "Dict[st
125125 :type request: ~pytest.FixtureRequest
126126
127127 :yields: A dictionary containing information relevant to the currently executing test.
128+ If the current test session is live but recording is disabled, yields None.
128129 """
129-
130- test_id , recording_id , variables = start_proxy_session ()
131-
132- # True if the function requesting the fixture is an async test
133- if iscoroutinefunction (request ._pyfuncitem .function ):
134- original_transport_func = await redirect_async_traffic (recording_id )
135- yield {"variables" : variables } # yield relevant test info and allow tests to run
136- restore_async_traffic (original_transport_func , request )
130+ if is_live_and_not_recording ():
131+ yield
137132 else :
138- original_transport_func = redirect_traffic (recording_id )
139- yield {"variables" : variables } # yield relevant test info and allow tests to run
140- restore_traffic (original_transport_func , request )
133+ test_id , recording_id , variables = start_proxy_session ()
141134
142- stop_record_or_playback (test_id , recording_id , variables )
135+ # True if the function requesting the fixture is an async test
136+ if iscoroutinefunction (request ._pyfuncitem .function ):
137+ original_transport_func = await redirect_async_traffic (recording_id )
138+ yield {"variables" : variables } # yield relevant test info and allow tests to run
139+ restore_async_traffic (original_transport_func , request )
140+ else :
141+ original_transport_func = redirect_traffic (recording_id )
142+ yield {"variables" : variables } # yield relevant test info and allow tests to run
143+ restore_traffic (original_transport_func , request )
144+
145+ stop_record_or_playback (test_id , recording_id , variables )
143146
144147
145148@pytest .fixture
@@ -162,16 +165,13 @@ def variable_recorder(recorded_test: "Dict[str, Any]") -> VariableRecorder:
162165# ----------HELPERS----------
163166
164167
165- def start_proxy_session () -> "Optional[ Tuple[str, str, Dict[str, str] ]]" :
168+ def start_proxy_session () -> "Tuple[str, str, Dict[str, str]]" :
166169 """Begins a playback or recording session and returns the current test ID, recording ID, and recorded variables.
167170
168171 :returns: A tuple, (a, b, c), where a is the test ID, b is the recording ID, and c is the `variables` dictionary
169172 that maps test variables to string values. If no variable dictionary was stored when the test was recorded, c is
170- an empty dictionary. If the current test session is live but recording is disabled, this returns None.
173+ an empty dictionary.
171174 """
172- if is_live_and_not_recording ():
173- return
174-
175175 test_id = get_test_id ()
176176 recording_id , variables = start_record_or_playback (test_id )
177177 return (test_id , recording_id , variables )
0 commit comments