如果答案是肯定的,那么一个关于如何使用它们的例子将是很棒的。
我指的是文档的以下部分:http://vcrpy.readthedocs.io/en/latest/advanced.html#register-your-own-request-matcher
发布于 2018-08-06 01:57:39
我自己找到了答案,答案是Yes
,当使用VCR.py时,可以有多个自定义匹配器。它实际上类似于VCRPY文档中使用单个自定义匹配器的显示方式。
下面是关于如何做到这一点的一般结构:
def vcr_matcher_1(r1, r2):
# logic for matching r1 and r2 requests
def vcr_matcher_2(r1, r2):
# logic for matching r1 and r2 requests
在您的录制代码中,您可以使用如下内容:
custom_vcr = vcr.VCR()
custom_vcr.register_matcher('vcr_matcher_1', vcr_matcher_1)
custom_vcr.register_matcher('vcr_matcher_2', vcr_matcher_2)
with custom_vcr.use_cassette('cassette_name.yml',
match_on = ['method', 'scheme', 'host', 'port', 'vcr_matcher_1', 'vcr_matcher_2']):
上面的示例还表明,您可以将自定义匹配器与VCR.py提供的默认匹配器混合使用
参考:
http://vcrpy.readthedocs.io/en/latest/advanced.html#register-your-own-request-matcher
https://stackoverflow.com/questions/51644278
复制相似问题