# keystoneauth1.fixture.keystoneauth_betamax module

A fixture to wrap the session constructor for use with Betamax.

class keystoneauth1.fixture.keystoneauth_betamax.BetamaxFixture(cassette_name: str, cassette_library_dir: str | None = None, serializer: type[~betamax.serializers.base.BaseSerializer] | None = None, record: bool | str = False, pre_record_hook: ~collections.abc.Callable[[~betamax.cassette.interaction.Interaction, ~betamax.cassette.cassette.Cassette], None] = <function pre_record_hook>, serializer_name: str | None = None, request_matchers: list[str] | None = None)

  Bases: `Fixture`

  __annotate_func__()

    The type of the None singleton.

  __annotations_cache__ = {'recorder': <class 'betamax.recorder.Betamax'>}
  __doc__ = None
  __firstlineno__ = 36
  __init__(cassette_name: str, cassette_library_dir: str | None = None, serializer: type[~betamax.serializers.base.BaseSerializer] | None = None, record: bool | str = False, pre_record_hook: ~collections.abc.Callable[[~betamax.cassette.interaction.Interaction, ~betamax.cassette.cassette.Cassette], None] = <function pre_record_hook>, serializer_name: str | None = None, request_matchers: list[str] | None = None) → None

    Configure Betamax for the test suite.

    Parameters:

      - cassette_name (str) – This is simply the name of the cassette without any file extension or containing directory. For example, to generate `keystoneauth1/tests/unit/data/example.yaml`, one would pass only `example`.

      - cassette_library_dir (str) – This is the directory that will contain all cassette files. In `keystoneauth1/tests/unit/data/example.yaml` you would pass `keystoneauth1/tests/unit/data/`.

      - serializer – A class that implements the Serializer API in Betamax. See also: https://betamax.readthedocs.io/en/latest/serializers.html

      - record – The Betamax record mode to use. If `False` (the default), then Betamax will not record anything. For more information about record modes, see: https://betamax.readthedocs.io/en/latest/record_modes.html

      - pre_record_hook (callable) – Function or callable to use to perform some handling of the request or response data prior to saving it to disk.

      - serializer_name (str) – The name of a serializer already registered with Betamax to use to handle cassettes. For example, if you want to use the default Betamax serializer, you would pass `'json'` to this parameter.

      - request_matchers (list) – The list of request matcher names to use with Betamax. Betamax’s default list is used if none are specified. See also: https://betamax.readthedocs.io/en/latest/matchers.html

  __module__ = 'keystoneauth1.fixture.keystoneauth_betamax'
  __static_attributes__ = ('_serializer_name', 'cassette_library_dir', 'cassette_name', 'mockpatch', 'pre_record_hook', 'record', 'serializer', 'use_cassette_kwargs')
  recorder: Betamax
  property serializer_name: str | None

    Determine the name of the selected serializer.

    If a class was specified, use the name attribute to generate this, otherwise, use the serializer_name parameter from `__init__`.

    Returns:

      Name of the serializer

    Return type:

      str

  setUp() → None

    Prepare the Fixture for use.

    This should not be overridden. Concrete fixtures should implement _setUp. Overriding of setUp is still supported, just not recommended.

    After setUp has completed, the fixture will have one or more attributes which can be used (these depend totally on the concrete subclass).

    Raises:

      MultipleExceptions if _setUp fails. The last exception captured within the MultipleExceptions will be a SetupError exception.

    Returns:

      None.

    Changed in 1.3:

      The recommendation to override setUp has been reversed - before 1.3, setUp() should be overridden, now it should not be.

    Changed in 1.3.1:

      BaseException is now caught, and only subclasses of Exception are wrapped in MultipleExceptions.

keystoneauth1.fixture.keystoneauth_betamax.__annotate__(format, /)

keystoneauth1.fixture.keystoneauth_betamax._construct_session_with_betamax(fixture: BetamaxFixture, session_obj: Session | None = None) → Session

this page last updated: 2026-07-14 15:48:40

Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.

found an error? report a bug