keystoneauth1.fixture.keystoneauth_betamax 模块¶
一个用于将会话构造函数包装起来以便与 Betamax 配合使用的 fixture。
- class keystoneauth1.fixture.keystoneauth_betamax.BetamaxFixture(cassette_name, cassette_library_dir=None, serializer=None, record=False, pre_record_hook=<function pre_record_hook>, serializer_name=None, request_matchers=None)
基础:
Fixture- __annotations__ = {}
- __doc__ = None
- __init__(cassette_name, cassette_library_dir=None, serializer=None, record=False, pre_record_hook=<function pre_record_hook>, serializer_name=None, request_matchers=None)
配置 Betamax 用于测试套件。
- 参数:
cassette_name (str) – 这只是磁带名称,不包含任何文件扩展名或包含目录。例如,要生成
keystoneauth1/tests/unit/data/example.yaml,只需传递example。cassette_library_dir (str) – 这是将包含所有磁带文件的目录。在
keystoneauth1/tests/unit/data/example.yaml中,您将传递keystoneauth1/tests/unit/data/。serializer – 一个实现 Betamax 中 Serializer API 的类。请参阅:https://betamax.readthedocs.io/en/2025.2/serializers.html
record – 要使用的 Betamax 记录模式。如果
False(默认值),则 Betamax 不会记录任何内容。有关记录模式的更多信息,请参阅:https://betamax.readthedocs.io/en/2025.2/record_modes.htmlpre_record_hook (callable) – 用于对请求或响应数据进行一些处理后再将其保存到磁盘的函数或可调用对象。
serializer_name (str) – 要用于处理磁带的已在 Betamax 中注册的序列化器的名称。例如,如果您想使用默认的 Betamax 序列化器,则将
'json'传递给此参数。request_matchers (list) – 要与 Betamax 一起使用的请求匹配器名称列表。如果没有指定,则使用 Betamax 的默认列表。请参阅:https://betamax.readthedocs.io/en/2025.2/matchers.html
- __module__ = 'keystoneauth1.fixture.keystoneauth_betamax'
- property serializer_name
确定所选序列化器的名称。
如果指定了类,则使用名称属性生成此名称,否则,使用
__init__中的 serializer_name 参数。- 返回值:
序列化器的名称
- 返回类型:
- setUp()
准备 Fixture 以供使用。
不应覆盖此方法。具体的 fixture 应该实现 _setUp。仍然支持覆盖 setUp,但不推荐。
在 setUp 完成后,fixture 将具有一个或多个属性,这些属性可用于(具体取决于具体的子类)。
- 引发:
如果 _setUp 失败,则引发 MultipleExceptions。MultipleExceptions 中捕获的最后一个异常将是一个 SetupError 异常。
- 返回值:
None。
- 更改于 1.3:
覆盖 setUp 的建议已反转 - 在 1.3 之前,应该覆盖 setUp(),现在不应该覆盖。
- 更改于 1.3.1:
现在捕获 BaseException,并且只有 Exception 的子类才会被包装在 MultipleExceptions 中。
- keystoneauth1.fixture.keystoneauth_betamax._construct_session_with_betamax(fixture, session_obj=None)