@@ -67,27 +67,38 @@ async def combined_call(*args, **kwargs):
6767 AioHttpTransport .send = combined_call
6868
6969 # call the modified function
70- # we define test_output before invoking the test so the variable is defined in case of an exception
71- test_output = None
70+ # we define test_variables before invoking the test so the variable is defined in case of an exception
71+ test_variables = None
72+ # this tracks whether the test has been run yet; used when calling the test function with/without `variables`
73+ # running without `variables` in the `except` block leads to unnecessary exceptions in test execution output
74+ test_run = False
7275 try :
7376 try :
74- test_output = await test_func (* args , variables = variables , ** trimmed_kwargs )
75- except TypeError :
76- logger = logging .getLogger ()
77- logger .info (
78- "This test can't accept variables as input. The test method should accept `**kwargs` and/or a "
79- "`variables` parameter to make use of recorded test variables."
80- )
81- test_output = await test_func (* args , ** trimmed_kwargs )
77+ test_variables = await test_func (* args , variables = variables , ** trimmed_kwargs )
78+ test_run = True
79+ except TypeError as error :
80+ if "unexpected keyword argument" in str (error ) and "variables" in str (error ):
81+ logger = logging .getLogger ()
82+ logger .info (
83+ "This test can't accept variables as input. The test method should accept `**kwargs` and/or a "
84+ "`variables` parameter to make use of recorded test variables."
85+ )
86+ else :
87+ raise error
88+ # if the test couldn't accept `variables`, run the test without passing them
89+ if not test_run :
90+ test_variables = await test_func (* args , ** trimmed_kwargs )
91+
8292 except ResourceNotFoundError as error :
8393 error_body = ContentDecodePolicy .deserialize_from_http_generics (error .response )
8494 message = error_body .get ("message" ) or error_body .get ("Message" )
8595 error_with_message = ResourceNotFoundError (message = message , response = error .response )
8696 raise error_with_message from error
97+
8798 finally :
8899 AioHttpTransport .send = original_transport_func
89- stop_record_or_playback (test_id , recording_id , test_output )
100+ stop_record_or_playback (test_id , recording_id , test_variables )
90101
91- return test_output
102+ return test_variables
92103
93104 return record_wrap
0 commit comments