1+ import logging
12import os
2- from typing import Coroutine , Generator , Any , Optional
3+ from typing import Optional
34
45import vcr
56import inspect
67
7- from vcr .cassette import CassetteContextDecorator
8-
98PYTHON_UPDATE_CASSETTE = os .getenv ("PYTHON_UPDATE_CASSETTE" , "false" ).lower () in ("1" , "true" , "yes" )
109
11- class ScwVCR (vcr .VCR ):
12- def use_cassette (self , path : Optional [str ] = None , ** kwargs ):
13- caller_file = inspect .stack ()[1 ].filename
14- cassette_dir = os .path .join (os .path .dirname (caller_file ), "cassettes" )
15- os .makedirs (cassette_dir , exist_ok = True )
16-
17- if path is None :
18- caller_name = os .path .splitext (os .path .basename (caller_file ))[0 ]
19- path = f"{ caller_name } .yaml"
20-
21- full_path = os .path .join (cassette_dir , path )
22- return super ().use_cassette (full_path , ** kwargs )
23-
10+ def func_path (function ):
11+ path = os .path .join (os .path .dirname (inspect .getfile (function )), "cassettes" )
12+ os .makedirs (path , exist_ok = True )
13+ filename = function .__name__ + ".cassette.yaml"
14+ return os .path .join (path , filename )
2415
25- scw_vcr = ScwVCR (
16+ scw_vcr = vcr . VCR (
2617 record_mode = "all" if PYTHON_UPDATE_CASSETTE else "none" ,
2718 filter_headers = ["x-auth-token" ],
19+ func_path_generator = func_path
2820)
0 commit comments